我试图在我的word文档头表中找到一个字符串。我可以找到这个范围,但是我想把这个范围所在的单元格存储到一个表中。细胞变量。
我该怎么做?
例如,在VBA中,要检索单元格的表#,行# &列号:
Sub GetCellRef()
Application.ScreenUpdating = False
Dim Rng As Range, t As Long, r As Long, c As Long
With ActiveDocument.Sections.First.Headers(wdHeaderFooterPrimary)
Set Rng = .Range
With .Range
With .Find
.Text = "Text to Find"
.Forward = True
.Wrap = wdFindStop
.MatchCase = False
.MatchWholeWord = True
.Execute
End With
If .Find.Found = True Then
If .Information(wdWithInTable) = True Then
Rng.End = .Cells(1).Range.End - 1
t = Rng.Tables.Count
Rng.Start = .Start
r = .Cells(1).RowIndex
c = .Cells(1).ColumnIndex
MsgBox Chr(34) & Rng.Text & Chr(34) & vbCr & _
"Found in table " & t & " at row " & r & " column " & c
End If
End If
End With
End With
Application.ScreenUpdating = True
End Sub