R
Ray C
I'm using Word VBA to retrieve email addresses inside a Word document. The
problem I encounter is that sometimes there are tabs, carriage returns, ie
special characters before and after the email address that also get pulled
and appear as small squares in the text that I retrieve. My logic is like
this:
1) Find occurence of @ sign.
2) Pull the sentence that contains the @ sign and use the Split function to
create an array of words in the sentence (one word will eventually contain
the full email address).
Problem: When I look at the array item that contains the email address,
there are also tabs, carriage returns, etc that get interpreted as small
squares in my output.
Here is 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)
For i = 0 To UBound(myArray)
If InStr(1, myArray(i), "@", vbTextCompare) <> 0 Then
If numEmailsFound < 3 Then
'/// Copy email address to excel.
End If
End If
Next i
End With
Loop
Next rngStory
problem I encounter is that sometimes there are tabs, carriage returns, ie
special characters before and after the email address that also get pulled
and appear as small squares in the text that I retrieve. My logic is like
this:
1) Find occurence of @ sign.
2) Pull the sentence that contains the @ sign and use the Split function to
create an array of words in the sentence (one word will eventually contain
the full email address).
Problem: When I look at the array item that contains the email address,
there are also tabs, carriage returns, etc that get interpreted as small
squares in my output.
Here is 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)
For i = 0 To UBound(myArray)
If InStr(1, myArray(i), "@", vbTextCompare) <> 0 Then
If numEmailsFound < 3 Then
'/// Copy email address to excel.
End If
End If
Next i
End With
Loop
Next rngStory