09-23-2024
07:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-23-2024
07:02 AM
Hi again,
i have now tried using ur code as a 1:1 on a new part file. I didnt change anything apart from the path and sheetname on line 21 and 22.
this is the error i get.
code used below:
Imports Microsoft.Office.Interop
AddReference "Microsoft.Office.Interop.Excel.dll"
Public Sub Main()
Dim oExcel As Excel.Application = GetExcel()
Dim oWB As Excel.Workbook = oExcel.Workbooks.Open(sExcelFile)
Dim oWS As Excel.Worksheet = oWB.Worksheets(sNameSheet)
Dim iRow As Integer = 2
Do While Not String.IsNullOrEmpty(oWS.Range("A" & iRow).Value)
MessageBox.Show(oWS.Range("A" & iRow).Value)
iRow += 1
Loop
oWB.Close()
oWS = Nothing
oWB = Nothing
oExcel = Nothing
End Sub
Property sExcelFile As String = "C:\Users\OP\Desktop\ProjektListe.xlsx"
Public sNameSheet As String = "Oversigt"
Private Function GetExcel(Optional bVisible As Boolean = False) As Excel.Application
Dim oXL As Microsoft.Office.Interop.Excel.Application
Dim oObj As Object = Nothing
Try
oObj = GetObject(, "Excel.Application")
oXL = TryCast(oObj, Microsoft.Office.Interop.Excel.Application)
Catch
oObj = CreateObject("Excel.Application")
oXL = TryCast(oObj, Microsoft.Office.Interop.Excel.Application)
End Try
oObj = Nothing
If oXL IsNot Nothing Then oXL.Visible = bVisible
Return oXL
End Function