我有一个启动用户窗体的 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
最佳答案
当然你可以在你的代码中使用 Excel VBA 函数——你可以使用 .Find
在你的 with block 内,像这样:
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
关于vba - 使用 Word 宏查找 Excel 行并引用该行中的其他单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21893792/