我想创建一个打开excel工作计划的脚本,在列'A‘中找到一个值,然后返回列'B’中的文本!在GE的iFIX中使用VBA!当我想将'MyValue‘声明为range时,他给出了一个错误消息。范围未知!这是我返回同一列的代码。有人能给出另一个解决方案吗?
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发布于 2017-08-10 18:52:12
在find方法中,您要求它将"FindString“作为字符串进行搜索。因为你想在FindString中找到值,所以你应该去掉"“。
Set MyValue = .Find(FindString, LookIn:=xlValues)您可能还希望将Findstring声明为字符串,以避免find方法出错。
https://stackoverflow.com/questions/45608045
复制相似问题