Hi,
I'm trying to create a macro from Reflection VB to read values from an excel sheet and pass them to the terminal. I'm just beginning but I've already found the first problem due to my lack of experience. The code is pasted below:
Dim Excel As Object
Sub Call_Excel()
Set Excel = CreateObject("excel.application")
Excel.Visible = True
TestIt
UserForm1.Show
Excel.Quit
Set Excel = Nothing
End Sub
Sub TestIt()
NewFN = Excel.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Excel.Workbooks.Open Filename:=NewFN
End If
End Sub
Private Sub UserForm_Initialize()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
Me.ComboBox1.AddItem sh.Name
Next
End Sub
I'm able to launch the excel app from reflection and make the workbook selection, but when the code should show the form with the combobox populated with the worksheet names I get an error in the form initialization.
Can anyone help me please!
Roser72
I'm trying to create a macro from Reflection VB to read values from an excel sheet and pass them to the terminal. I'm just beginning but I've already found the first problem due to my lack of experience. The code is pasted below:
Dim Excel As Object
Sub Call_Excel()
Set Excel = CreateObject("excel.application")
Excel.Visible = True
TestIt
UserForm1.Show
Excel.Quit
Set Excel = Nothing
End Sub
Sub TestIt()
NewFN = Excel.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Excel.Workbooks.Open Filename:=NewFN
End If
End Sub
Private Sub UserForm_Initialize()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
Me.ComboBox1.AddItem sh.Name
Next
End Sub
I'm able to launch the excel app from reflection and make the workbook selection, but when the code should show the form with the combobox populated with the worksheet names I get an error in the form initialization.
Can anyone help me please!
Roser72