我在Excel中编写了一个VBA,以在Microsoft Word中找到一个特定的单词,并将该关键字下面的表的一部分重新返回到Excel,但是它给出了运行时错误424“需要对象”,您的帮助将非常感谢。谢谢!
Option Explicit
Sub Test()
Dim ws As Worksheet
Dim objWord As Object
Dim i As Integer
Dim strValue As String
Dim wdDoc As Word.Document
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set wdDoc = objWord.Documents.Open("C:\Users\Nigel\Desktop\Testt.docx")
objWord.Activate
With objWord.Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = True
.Wrap = wdFindContinue
.Execute FindText:="Test"
End With
If objWord.Selection.Find.Execute = True Then
MsgBox ("Found")
Else
MsgBox ("Not found")
End If
TableNo = objWord.Selection.Tables.Count
Dim a As Object
Set a = objWord.Selection.Range.Next(Unit:=TableNo, Count:=1)
Dim x As Long, y As Long
x = 1: y = 1
With a
For rowNb = 1 To 1
For colNb = 2 To 2
Cells(x, y) = WorksheetFunction.Clean(.Cell(rowNb, colNb).Range.Text)
y = y + 1
Next colNb
y = 1
x = x + 1
Next rowNb
End With
x = x + 2
End Sub
此行上的对象必需的运行时错误424:
Cells(x, y) = WorksheetFunction.Clean(.Cell(rowNb, colNb).Range.Text)
答案 0 :(得分:0)
为避免注释的顺序过多,请尝试以下代码作为您应该去往何处的指南。可能仍然有一些问题需要解决,以得到您正在考虑的逻辑,而不是我对它的解释。
const filteredData = this.state.itemsWithPrice.map(x => data.includes(x.market_hash_name));
filteredData.map(n => <li>{x.price}</li>);