A VB module uses the Word object model. Late bound objects. I'm
searching for hidden text. At a certain point, my code simply hangs. I
have error trapping in place, but no exceptions occur. But if I pause
the program and try to evaluate my range object (rng), to see what's up,
I get a message "Expression cannot be evaluated at this time." in the
immediate window.
With minor differences, the code I'm using is pasted from a working VB6
app. Ideas? Here's the code. Ignore the "config.AddItemNode" function,
it just is writing information to a structure so I can display it later.
Dim rng As Object
Dim bOK As Boolean
Dim sBuf As String
Dim bRet As Boolean
Const wdActiveEndPageNumber = 3
Const wdFirstCharacterLineNumber = 10
' moDoc is my document (word.application.activedocument)
For Each rng In moDoc.StoryRanges
Try
rng.TextRetrievalMode.IncludeHiddenText = True
Catch ex As Exception
log.LogErr(ex)
Exit For
End Try
With rng.Find
.ClearFormatting()
.Font.Hidden = True
.Text = ""
.wrap = wdFindContinue
bOK = .Execute
Do While bOK
sBuf = ""
' same code as in VB6... but not working here.
Try
' THIS IS WHERE IT KEEPS "STICKING",
' at the evaluation of rng.text
If (rng Is Nothing) Then
Else
If (rng.Text Is Nothing) Then
Else
sBuf = rng.Text
sBuf = StripString(sBuf)
End If
End If
Catch ex As Exception
log.LogErr(ex)
End Try
If (sBuf = Nothing) Then sBuf = ""
If sBuf.Length > 0 Then
' exclude paragraph marks
If sBuf.Length = 1 And Asc(sBuf) = 13 Then
' don't display as a line item
Else
Try
Dim itempath = config.AddItemNode(xpath,
"hidden", "")
config.AddItemNode(itempath, "Text", sBuf)
config.AddItemNode(itempath, "Location",
GetStoryTypeDesc(rng.storytype))
config.AddItemNode(itempath, "Page",
Convert.ToString(rng.Information(wdActiveEndPageNu mber)))
config.AddItemNode(itempath, "Line",
Convert.ToString(rng.Information(wdFirstCharacterL ineNumber)))
Catch ex As Exception
config.AddItemNode(xpath, "security error",
"Can't display details due to document security.")
Exit Do
End Try
End If
.wrap = wdFindStop
bOK = .Execute
End If
Loop
End With
Next rng