C
Charles DiGiovanna
Since I've not had any reply to my initial inquiry on this issue I've
decided to expand on it in hopes that someone can help.
The code that's failing is called by the line
FormatMsgText oMessage.ReceivedTime, oMessage.Body, oMessage.SenderName
In the procedure that selects the messages to be processed. (attached)
The code itself is:
*************************************
Public Sub FormatMsgText(RDate As Date, RBody As String, RSender As String)
' Declare for Word
Dim MyWordApp As Word.Application
Dim MyWordDocument As Word.Document
Dim MyStoryRange As Word.Range: Dim MyDateRange As Word.Range: Dim
MySenderRange As Word.Range
Dim R As Word.Range
' Create a new document for the message content
Set MyWordApp = New Word.Application
Set MyWordDocument = Documents.Add
Set MyStoryRange = MyWordDocument.StoryRanges(wdMainTextStory)
'Replace the plus signs in the text with spaces
MyStoryRange.Text = RDate & " " & RSender & RBody
On Error GoTo eHandler
With MyStoryRange.Find
..Text = "+"
..Replacement.Text = " "
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
End With
MyStoryRange.Find.Execute Replace:=wdReplaceAll
' Print the reformatted message
ActiveDocument.PrintOut
' Clean up and close up
MyWordApp.Quit
Set MyWordDocument = Nothing
Set MyWordApp = Nothing
Exit Sub
' error handling code
eHandler:
MyWordApp.Quit
If Err = 5 Then
MsgBox ("Error 5")
Else
MsgBox ("Error Number = " + Err)
End If
End Sub
******************************
This seems to me to be perfectly straightforward code and the With...End
With loop works just fine if I use it in a procedure in a Word macro.
A Watch on the variable MyStoryRange shows that it contains the text that I
expect it to contain so that it's apparently ready to be handled by the With
loop. Yet, the procedure fails every time when called from the procedure in
the attachment. I get an Error 5 message.
Please help.
Thanks.
CVDG
decided to expand on it in hopes that someone can help.
The code that's failing is called by the line
FormatMsgText oMessage.ReceivedTime, oMessage.Body, oMessage.SenderName
In the procedure that selects the messages to be processed. (attached)
The code itself is:
*************************************
Public Sub FormatMsgText(RDate As Date, RBody As String, RSender As String)
' Declare for Word
Dim MyWordApp As Word.Application
Dim MyWordDocument As Word.Document
Dim MyStoryRange As Word.Range: Dim MyDateRange As Word.Range: Dim
MySenderRange As Word.Range
Dim R As Word.Range
' Create a new document for the message content
Set MyWordApp = New Word.Application
Set MyWordDocument = Documents.Add
Set MyStoryRange = MyWordDocument.StoryRanges(wdMainTextStory)
'Replace the plus signs in the text with spaces
MyStoryRange.Text = RDate & " " & RSender & RBody
On Error GoTo eHandler
With MyStoryRange.Find
..Text = "+"
..Replacement.Text = " "
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
End With
MyStoryRange.Find.Execute Replace:=wdReplaceAll
' Print the reformatted message
ActiveDocument.PrintOut
' Clean up and close up
MyWordApp.Quit
Set MyWordDocument = Nothing
Set MyWordApp = Nothing
Exit Sub
' error handling code
eHandler:
MyWordApp.Quit
If Err = 5 Then
MsgBox ("Error 5")
Else
MsgBox ("Error Number = " + Err)
End If
End Sub
******************************
This seems to me to be perfectly straightforward code and the With...End
With loop works just fine if I use it in a procedure in a Word macro.
A Watch on the variable MyStoryRange shows that it contains the text that I
expect it to contain so that it's apparently ready to be handled by the With
loop. Yet, the procedure fails every time when called from the procedure in
the attachment. I get an Error 5 message.
Please help.
Thanks.
CVDG