我有一个启动UserForm的Word宏。
我正在尝试添加一项功能来更新外部Excel文档中的某些字段。 不幸的是,Word宏无法识别许多Excel VBA命令。
这是一个想法:
我在这里:
Private Sub updateForm_Click()
'Start by parsing the Test Tracking spreadsheet
Set appExcel = CreateObject("Excel.Application")
Dim testTrack_File As Variant
Dim Rng As Range
Dim RowCrnt As Long
testTrack_File = "FileName.exe"
appExcel.Workbooks.Open testTrack_File
'Search Test Tracking spreadsheet for the Vendor
With appExcel.Sheets("Testing_Queue")
'Code Needed here
docField =
End With
appExcel.ActiveWorkbook.Close
appExcel.Quit
Set appExcel = Nothing
End Sub
答案 0 :(得分:1)
当然,您可以在代码中使用Excel VBA函数 - 您可以在with块中使用.Find
,如下所示:
With appExcel.Sheets("Testing_Queue")
Dim xlCell As Object
Set xlCell = .Cells.Find("asdf")
'Get the row where the value was found
Dim xlRow As Integer
xlRow = xlCell.Row
'change the target column to whichever you want
Dim xlCol As Integer
xlCol = 6
Dim targetCellValue
targetCellValue = .Cells(xlRow, xlCol).Value
MsgBox (targetCellValue)
End With