As posted in my other recent thread, I'm working on a macro which is being run from a non-office application. Via a form, it will allow the user to browse and select an xlsx file which is then opened without being visible. A list box on the form then displays the worksheet names (a max of 3 will be displayed) and when the user click's on any of those, values of specific cells from the worksheet selected in the first listbox1 will be displayed in listbox2.
Now because this macro isnt hosted in the Excel IDE I have referenced the MicroSoft Excel 16.0 Object Library. I have also made the following declarations:
In the first listbox click event I have the following code:
ReadValues is a function which I intend find the last row with data in Column A on the worksheet that is selected in the first listbox (LB_TrackName). Originally the first 2 lines of the LB_TrackName_Click event procedure read:
This however gave me the error Method of 'Sheets' of object '_Global' so I added the oXlWkBk prefix. Not sure if I needed to but it made sense to add it giving that sheets isnt part of the parent IDE object library and I think its made that error go away but now I have the error listed in the thread title.
Any idea what I need to do to proceed?
Now because this macro isnt hosted in the Excel IDE I have referenced the MicroSoft Excel 16.0 Object Library. I have also made the following declarations:
Code:
Public sWorkbookFullName As String
Public oXlApp As excel.Application
Public oXlWkBk As excel.Workbook
Public oXlWkSht As excel.Worksheet
Public ShtMain As excel.Worksheet
Public ShtRelief As excel.Worksheet
Public Shtother As excel.Worksheet
In the first listbox click event I have the following code:
Code:
Private Sub LB_TrackName_Click()
Set ShtMain = oXlWkBk.Sheets("Main")
Set ShtRelief = oXlWkBk.Sheets("Relief")
FrmPWayLevel.LB_TrackDirection.Clear
If FrmPWayLevel.LB_TrackName.Value = "Main" Then
FrmPWayLevel.LB_TrackDirection.AddItem ShtMain.Range("B1").Value
FrmPWayLevel.LB_TrackDirection.AddItem ShtMain.Range("J1").Value
ReadValues
ElseIf LB_TrackName.Text = "Relief" Then
FrmPWayLevel.LB_TrackDirection.AddItem ShtRelief.Range("B1").Value
FrmPWayLevel.LB_TrackDirection.AddItem ShtRelief.Range("J1").Value
Else
FrmPWayLevel.LB_TrackDirection.AddItem "other"
End If
End Sub
ReadValues is a function which I intend find the last row with data in Column A on the worksheet that is selected in the first listbox (LB_TrackName). Originally the first 2 lines of the LB_TrackName_Click event procedure read:
Code:
Set ShtMain = Sheets("Main")
Set ShtRelief = Sheets("Relief")
This however gave me the error Method of 'Sheets' of object '_Global' so I added the oXlWkBk prefix. Not sure if I needed to but it made sense to add it giving that sheets isnt part of the parent IDE object library and I think its made that error go away but now I have the error listed in the thread title.
Any idea what I need to do to proceed?