使用Wordmacros查找Excel行并引用该行中的其他单元格

我有一个启动用户窗体的Wordmacros。

我想添加一个function来更新外部Excel文档中的某些字段。 不幸的是,Wordmacros不能识别许多Excel VBA命令。

这是这个想法:

  1. search关键字“供应商”的Excel电子表格。
  2. 确定其行(RowCrnt)。
  3. 将该行中特定列的内容返回到单词macros(docField)。

这是我在哪里:

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函数 – 你可以使用。在你的block中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