R
Ray C
I need to find all emails inside a Word document. The problem is that when
the document is protected, I can't read the Text property of the range. I get
an error saying that the document is protected (Error #4605). All I'm doing
is reading, I'm not modifying anything. I use the Split function to get the
sentence of words where the @ sign was found, then I loop through the
elements of my array until I get to the one that has the @ sign. It's this
line that causes the error.
Here part of my code:
For Each rngStory In objDocument.StoryRanges
With rngStory.Find
.ClearFormatting
.Text = "@"
.Wrap = wdFindStop
.Forward = True
End With
Do Until rngStory.Find.Execute = False
With rngStory.Duplicate
.Expand Unit:=wdSentence
myArray = Split(.Text, " ", -1, vbTextCompare) '///
Error here !!!
If UBound(myArray) <> -1 Then
For i = 0 To UBound(myArray)
If InStr(1, myArray(i), "@", vbTextCompare) <> 0
Then
'/// ... Process Email here
numEmailsFound = numEmailsFound + 1
End If
Next i
End If
End With
Loop
Next rngStory
the document is protected, I can't read the Text property of the range. I get
an error saying that the document is protected (Error #4605). All I'm doing
is reading, I'm not modifying anything. I use the Split function to get the
sentence of words where the @ sign was found, then I loop through the
elements of my array until I get to the one that has the @ sign. It's this
line that causes the error.
Here part of my code:
For Each rngStory In objDocument.StoryRanges
With rngStory.Find
.ClearFormatting
.Text = "@"
.Wrap = wdFindStop
.Forward = True
End With
Do Until rngStory.Find.Execute = False
With rngStory.Duplicate
.Expand Unit:=wdSentence
myArray = Split(.Text, " ", -1, vbTextCompare) '///
Error here !!!
If UBound(myArray) <> -1 Then
For i = 0 To UBound(myArray)
If InStr(1, myArray(i), "@", vbTextCompare) <> 0
Then
'/// ... Process Email here
numEmailsFound = numEmailsFound + 1
End If
Next i
End If
End With
Loop
Next rngStory