I want to create a script opening a excel workscheet, find a value in column 'A' and returns the text in column 'B' ! Using VBA in iFIX from GE ! When I want to declare 'MyValue' as range, he gives a fault message. Range is unknown ! This is my code to return the same column. Someone to give another solution?
Private Sub OPEN_MSG_Click()
Dim FindString$
Dim MyValue
Dim objExcel, objsheet, WB,WS As Object
'Open excel file
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
Set WB = objExcel.Workbooks.Open("C:\Program Files (x86)\Proficy\Proficy iFIX\ProjectBackup\Foutcode_Opgezuiverd.xlsx")
WB.ACTIVATE
Set WS = WB.Worksheets("Blad1")
'Set objsheet = objExcel.ActiveWorkbook.Worksheets(1)
FindString = InputBox("Enter a Search value")
With WS.Range("A1:A800")
Set MyValue = .Find("FindString", LookIn:=xlValues)
If Not MyValue Is Nothing Then
MsgBox MyValue.Column
MsgBox MyValue.row
End If
End With
' Save the spreadsheet and close the workbook.
objExcel.ActiveWorkbook.Close
' Quit Excel.
objExcel.Application.Quit
End Sub
Rangeis only a datatype in Excel. Just leave it asVariant.