Random sig from Word file

  • Thread starter Thread starter Sriram N A \(MICO/PJ-SAP-PP\) *
  • Start date Start date
S

Sriram N A \(MICO/PJ-SAP-PP\) *

I'm trying to roll a home-grown random sig generator to use with Outlook and
I've gotten thus far:

Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
With item
'Set Reference to Microsoft Word 11.0 Object Library
Dim Source As Document, findtext As Range
Dim iParCount As Long, iSigPara As Long
Const MyDoc = "C:\Documents and Settings\Desktop\Proverbs.doc"
Set Source = Documents.Open(MyDoc)
iParCount = Source.Paragraphs.Count
iSigPara = CLng(Rnd * iParCount)
Set findtext = Source.Paragraphs(iSigPara).Range
..HTMLBody = .HTMLBody & findtext
Source.Close
End With
End Sub

The problem is, the extract from the Word document loses formatting with
this approach. What's the best way of appending this text to the message
with all formatting?
 
I'm almost there by using the Word object model to manipulate the Outlook
message body, but it is misbehaving badly (Word is set as the email editor):

Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
Dim CC As Document
Dim Source As Document, findtext As Range
Dim iParCount As Long, iSigPara As Long
Const MyDoc = "C:\Documents and Settings\Desktop\proverbs.doc"
With item
Set CC = .GetInspector.WordEditor
Set Source = Documents.Open(MyDoc)
iParCount = Source.Paragraphs.Count
iSigPara = CLng(Rnd * iParCount)
Set findtext = Source.Paragraphs(iSigPara).Range
findtext.Copy
CC.Content.Collapse Direction:=wdCollapseEnd
CC.Content.Paste
Source.Close
End With
End Sub

I presume the Collapse method positions the insertion point after the body
of the message for the Paste operation, but it invariably overwrites the
message body... and bothers me with a prompt to save the message.

I'm trying to get a random paragraph from a Word file appended to outgoing
Outlook messages, keeping the Word formatting.
 
Back
Top