Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. Imports System.Drawing
  2. Imports System.Runtime.InteropServices
  3.  
  4. Module Module1
  5.  
  6. Sub Main()
  7. Dim fileName As String = "C:\Users\PFerro00\Desktop\Q8\Marketing consolidated non-operational Reporting\Input\Spese NEW\SPESE_YTD 1819 BUDGET.xls"
  8. Dim xlApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application()
  9. Dim xlWorkbook As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Open(fileName)
  10. Dim numSheets As Integer = xlWorkbook.Sheets.Count
  11. 'Dim xlWorksheet As Microsoft.Office.Interop.Excel.Worksheet = xlWorkbook.Sheets(3)
  12. Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing
  13. 'xlWorksheet = xlWorkbook.Sheets(3)
  14. 'xlWorkSheets=xlWorkBook.Sheets
  15. xlWorkSheet = CType(xlWorkbook.Sheets(3), Microsoft.Office.Interop.Excel.Worksheet)
  16.  
  17. Dim xlRange As Microsoft.Office.Interop.Excel.Range = xlWorkSheet.UsedRange
  18. Dim rowCount As Integer = xlRange.Rows.Count 'dt.Rows.Count
  19. Dim colCount As Integer = xlRange.Columns.Count 'dt.Columns.Count
  20.  
  21. For i As Integer = 1 To rowCount
  22. For j As Integer = 1 To colCount
  23. Dim myCell As Microsoft.Office.Interop.Excel.Range = DirectCast(xlWorkSheet.Cells(i, j), Microsoft.Office.Interop.Excel.Range)
  24. Dim myInteriorColor As Color = System.Drawing.ColorTranslator.FromOle(CInt(myCell.Interior.Color))
  25. Dim myHtmlColor As String = System.Drawing.ColorTranslator.ToHtml(myInteriorColor)
  26. ' Dim myCellText As String = DirectCast(myCell.Value2, String)
  27. Dim myFormula As String = DirectCast(myCell.Formula, String)
  28. If myHtmlColor = "#CCFFCC" And myFormula.Trim <> "" Then
  29. ' myCell.Value = myCellText.Replace("]02", "]03")
  30. myCell.Formula = myFormula.Replace("]01", "]02")
  31. End If
  32. Next
  33. Next
  34.  
  35. GC.Collect()
  36. GC.WaitForPendingFinalizers()
  37. Marshal.ReleaseComObject(xlWorkSheet)
  38. xlWorkbook.Close()
  39. Marshal.ReleaseComObject(xlWorkbook)
  40. xlApp.Quit()
  41. Marshal.ReleaseComObject(xlApp)
  42.  
  43. End Sub
  44.  
  45. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement