E
Eddy Beuckelaers
I have to search the first cell of the first table in each section of a
multi-section document for words in Arial Black.
I tried code like this:
With doc.Sections(intSection).Range.Tables(1).Cell(1, 1).Range.Find
.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Name = "Arial Black"
Do While .Execute
strTag = .Parent.Text
...
Loop
End With
If the cell doesn't contain Arial Black, all is ok. Find doesn't go beyond
the cell. But when it does contain a word in Arial Black, the first
occurence is correctly passed to the variable, but subsequent Executes in
the loop go beyond the cell boundaries. I understand this is because Execute
redefines the range to the text found when successfull.
I can make the loop work with below changes, basically checking is the found
range is still withing the same cell. But that makes the algorithm
unacceptably slow. I realize I can optimize the loop by not evaluating all
four Information data when the first ones fail, but my solution seems so
complicated for a not so far fetched task. Any other ideas?
Tx,
Eddy.
Set rngWordFind = doc.Sections(intSection).Range.Tables(1).Cell(1, 1).Range
With rngWordFind.Find
.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Name = "Arial Black"
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
blnInfoWithinTable = rngWordFind.Information(wdWithInTable)
intInfoSection = rngWordFind.Information(wdActiveEndSectionNumber)
intInfoCol = rngWordFind.Information(wdStartOfRangeColumnNumber)
intInfoRow = rngWordFind.Information(wdStartOfRangeRowNumber)
If blnInfoWithinTable = True And intInfoSection = intSection And
intInfoRow = 1 And intInfoCol = 2 Then
strTag = rngWordFind.Find.Parent.Text
Else
Exit Do
End If
Loop
End With
multi-section document for words in Arial Black.
I tried code like this:
With doc.Sections(intSection).Range.Tables(1).Cell(1, 1).Range.Find
.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Name = "Arial Black"
Do While .Execute
strTag = .Parent.Text
...
Loop
End With
If the cell doesn't contain Arial Black, all is ok. Find doesn't go beyond
the cell. But when it does contain a word in Arial Black, the first
occurence is correctly passed to the variable, but subsequent Executes in
the loop go beyond the cell boundaries. I understand this is because Execute
redefines the range to the text found when successfull.
I can make the loop work with below changes, basically checking is the found
range is still withing the same cell. But that makes the algorithm
unacceptably slow. I realize I can optimize the loop by not evaluating all
four Information data when the first ones fail, but my solution seems so
complicated for a not so far fetched task. Any other ideas?
Tx,
Eddy.
Set rngWordFind = doc.Sections(intSection).Range.Tables(1).Cell(1, 1).Range
With rngWordFind.Find
.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.Font.Name = "Arial Black"
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
blnInfoWithinTable = rngWordFind.Information(wdWithInTable)
intInfoSection = rngWordFind.Information(wdActiveEndSectionNumber)
intInfoCol = rngWordFind.Information(wdStartOfRangeColumnNumber)
intInfoRow = rngWordFind.Information(wdStartOfRangeRowNumber)
If blnInfoWithinTable = True And intInfoSection = intSection And
intInfoRow = 1 And intInfoCol = 2 Then
strTag = rngWordFind.Find.Parent.Text
Else
Exit Do
End If
Loop
End With