A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How to copy the format in word document to Outlook Mail



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 3rd 06, 04:36 PM posted to microsoft.public.outlook.program_vba
Sangeeta Michael
external usenet poster
 
Posts: 5
Default How to copy the format in word document to Outlook Mail

Hi,
I am trying to develop an application that creates a word object and then
generates a letter based on the data pulled out from the database. I need to
then send this letter from Outlook.
My code executes what i want it to but my problem is
1) i am creating a new table into an existing form (This does not keep the
font of the existing form)
2) When i pull the created document into outlook, it does not keep the
formatting, neither does it display the table.
I will give the code i have used for this process
Could some one help me with this?

Public Function EmailLetterTest()
On Error GoTo Failed
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

Set con = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
'Get the data to be printed
rs.Open "select * from tTrainingSchedule where id=1", con

If rs.RecordCount = 0 Then
MsgBox "No data found"
Exit Function
End If

rs.MoveFirst
'************************************************* *******
'GENERATE LETTER
'Create Object for the new Word Application
Dim myWordObj As Object
Dim doc1 As Document
Set myWordObj = CreateObject("WORD.APPLICATION")
myWordObj.Visible = True



myWordObj.Documents.Add "F:\APPS\Colossus
II\Documents\TrainingConfirmationLetter.doc"
With myWordObj.Selection
.EndKey 6, 0
'.typetext Text:="Sangeeta Noby"
'.typeparagraph
myWordObj.ActiveDocument.Tables.Add
Range:=myWordObj.Selection.Range, NumRows:=1, NumColumns:=6,
DefaultTableBehavior:=2, AutoFitBehavior:=0
'.MoveRight unit:=12
.typetext Text:="Date"
.MoveRight unit:=12
.typetext Text:="Number of Participants"
.MoveRight unit:=12
.typetext Text:="Start Time"
.MoveRight unit:=12
.typetext Text:="End Time"
.MoveRight unit:=12
.typetext Text:="Estimated Amount"
.MoveRight unit:=12
.typetext Text:="Training Location"

.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("AllottedDate"))
.MoveRight unit:=12
.typetext Text:="1"
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedStartTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedEndTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("EstimatedAmount"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("TrainingLocation"))
'.Kind = wdEMail
End With


'************************************************* ***********
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
'GENERATE E-MAIL
Dim objOutlook As Outlook.Application
Dim aNamespace As NameSpace
Dim aFolder As MapiFolder
Dim aItems As Items
Dim aNewItem As Outlook.MailItem

Set objOutlook = CreateObject("OUTLOOK.APPLICATION")
Set aNamespace = objOutlook.GetNamespace("MAPI")
Set aFolder = aNamespace.GetDefaultFolder(OLFolderInbox)
Set aItems = aFolder.Items
Set aNewItem = objOutlook.CreateItem(OLMailitem)

With aNewItem
.Subject = "Testing"
.To = "
.BodyFormat = olFormatRichText 'I tried HTML and the other options does
no luk
.Body = myWordObj.Documents(1).Content
.Display
End With

Set myWordObj = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Exit Function
Failed:
HandleError Err.Description, Err.Number, Err.Source, "test:EmailLetterTest"
End Function

  #2  
Old October 3rd 06, 05:13 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default How to copy the format in word document to Outlook Mail

Try setting Outlook to use Word as the e-mail editor for new messages and see
if the formatting is better.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

Hi,
I am trying to develop an application that creates a word object and then
generates a letter based on the data pulled out from the database. I need to
then send this letter from Outlook.
My code executes what i want it to but my problem is
1) i am creating a new table into an existing form (This does not keep the
font of the existing form)
2) When i pull the created document into outlook, it does not keep the
formatting, neither does it display the table.
I will give the code i have used for this process
Could some one help me with this?

Public Function EmailLetterTest()
On Error GoTo Failed
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

Set con = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
'Get the data to be printed
rs.Open "select * from tTrainingSchedule where id=1", con

If rs.RecordCount = 0 Then
MsgBox "No data found"
Exit Function
End If

rs.MoveFirst
'************************************************* *******
'GENERATE LETTER
'Create Object for the new Word Application
Dim myWordObj As Object
Dim doc1 As Document
Set myWordObj = CreateObject("WORD.APPLICATION")
myWordObj.Visible = True



myWordObj.Documents.Add "F:\APPS\Colossus
II\Documents\TrainingConfirmationLetter.doc"
With myWordObj.Selection
.EndKey 6, 0
'.typetext Text:="Sangeeta Noby"
'.typeparagraph
myWordObj.ActiveDocument.Tables.Add
Range:=myWordObj.Selection.Range, NumRows:=1, NumColumns:=6,
DefaultTableBehavior:=2, AutoFitBehavior:=0
'.MoveRight unit:=12
.typetext Text:="Date"
.MoveRight unit:=12
.typetext Text:="Number of Participants"
.MoveRight unit:=12
.typetext Text:="Start Time"
.MoveRight unit:=12
.typetext Text:="End Time"
.MoveRight unit:=12
.typetext Text:="Estimated Amount"
.MoveRight unit:=12
.typetext Text:="Training Location"

.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("AllottedDate"))
.MoveRight unit:=12
.typetext Text:="1"
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedStartTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedEndTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("EstimatedAmount"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("TrainingLocation"))
'.Kind = wdEMail
End With


'************************************************* ***********
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
'GENERATE E-MAIL
Dim objOutlook As Outlook.Application
Dim aNamespace As NameSpace
Dim aFolder As MapiFolder
Dim aItems As Items
Dim aNewItem As Outlook.MailItem

Set objOutlook = CreateObject("OUTLOOK.APPLICATION")
Set aNamespace = objOutlook.GetNamespace("MAPI")
Set aFolder = aNamespace.GetDefaultFolder(OLFolderInbox)
Set aItems = aFolder.Items
Set aNewItem = objOutlook.CreateItem(OLMailitem)

With aNewItem
.Subject = "Testing"
.To = "
.BodyFormat = olFormatRichText 'I tried HTML and the other options does
no luk
.Body = myWordObj.Documents(1).Content
.Display
End With

Set myWordObj = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Exit Function
Failed:
HandleError Err.Description, Err.Number, Err.Source, "test:EmailLetterTest"
End Function

  #3  
Old October 3rd 06, 05:25 PM posted to microsoft.public.outlook.program_vba
Sangeeta Michael
external usenet poster
 
Posts: 5
Default How to copy the format in word document to Outlook Mail

No luck
The table comes out like this

Date
Number of Participants
Start Time
End Time
Estimated Amount
Training Location

10/1/2006
1
9:00 AM
1:00 PM
1100
3


"Eric Legault [MVP - Outlook]" wrote:

Try setting Outlook to use Word as the e-mail editor for new messages and see
if the formatting is better.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

Hi,
I am trying to develop an application that creates a word object and then
generates a letter based on the data pulled out from the database. I need to
then send this letter from Outlook.
My code executes what i want it to but my problem is
1) i am creating a new table into an existing form (This does not keep the
font of the existing form)
2) When i pull the created document into outlook, it does not keep the
formatting, neither does it display the table.
I will give the code i have used for this process
Could some one help me with this?

Public Function EmailLetterTest()
On Error GoTo Failed
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

Set con = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
'Get the data to be printed
rs.Open "select * from tTrainingSchedule where id=1", con

If rs.RecordCount = 0 Then
MsgBox "No data found"
Exit Function
End If

rs.MoveFirst
'************************************************* *******
'GENERATE LETTER
'Create Object for the new Word Application
Dim myWordObj As Object
Dim doc1 As Document
Set myWordObj = CreateObject("WORD.APPLICATION")
myWordObj.Visible = True



myWordObj.Documents.Add "F:\APPS\Colossus
II\Documents\TrainingConfirmationLetter.doc"
With myWordObj.Selection
.EndKey 6, 0
'.typetext Text:="Sangeeta Noby"
'.typeparagraph
myWordObj.ActiveDocument.Tables.Add
Range:=myWordObj.Selection.Range, NumRows:=1, NumColumns:=6,
DefaultTableBehavior:=2, AutoFitBehavior:=0
'.MoveRight unit:=12
.typetext Text:="Date"
.MoveRight unit:=12
.typetext Text:="Number of Participants"
.MoveRight unit:=12
.typetext Text:="Start Time"
.MoveRight unit:=12
.typetext Text:="End Time"
.MoveRight unit:=12
.typetext Text:="Estimated Amount"
.MoveRight unit:=12
.typetext Text:="Training Location"

.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("AllottedDate"))
.MoveRight unit:=12
.typetext Text:="1"
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedStartTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedEndTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("EstimatedAmount"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("TrainingLocation"))
'.Kind = wdEMail
End With


'************************************************* ***********
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
'GENERATE E-MAIL
Dim objOutlook As Outlook.Application
Dim aNamespace As NameSpace
Dim aFolder As MapiFolder
Dim aItems As Items
Dim aNewItem As Outlook.MailItem

Set objOutlook = CreateObject("OUTLOOK.APPLICATION")
Set aNamespace = objOutlook.GetNamespace("MAPI")
Set aFolder = aNamespace.GetDefaultFolder(OLFolderInbox)
Set aItems = aFolder.Items
Set aNewItem = objOutlook.CreateItem(OLMailitem)

With aNewItem
.Subject = "Testing"
.To = "
.BodyFormat = olFormatRichText 'I tried HTML and the other options does
no luk
.Body = myWordObj.Documents(1).Content
.Display
End With

Set myWordObj = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Exit Function
Failed:
HandleError Err.Description, Err.Number, Err.Source, "test:EmailLetterTest"
End Function

  #4  
Old October 3rd 06, 07:50 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default How to copy the format in word document to Outlook Mail

You're right, I tried - doesn't work.

The easiest way to do this is without code - in Word, choose File - Send To
- Mail Recipient. Recipients will get exactly what you see in the Word
document in the e-mail message body.

Otherwise, you'd need to build your Word document in Outlook and use Word as
the e-mail editor. You can use the Inspector.WordEditor property to get a
handle to a Word.Document object and use Word VBA in your Outlook VBA Editor
to build the document contents, and then you'll have full control
programmatically over the sending of the e-mail.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

No luck
The table comes out like this

Date
Number of Participants
Start Time
End Time
Estimated Amount
Training Location

10/1/2006
1
9:00 AM
1:00 PM
1100
3


"Eric Legault [MVP - Outlook]" wrote:

Try setting Outlook to use Word as the e-mail editor for new messages and see
if the formatting is better.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

Hi,
I am trying to develop an application that creates a word object and then
generates a letter based on the data pulled out from the database. I need to
then send this letter from Outlook.
My code executes what i want it to but my problem is
1) i am creating a new table into an existing form (This does not keep the
font of the existing form)
2) When i pull the created document into outlook, it does not keep the
formatting, neither does it display the table.
I will give the code i have used for this process
Could some one help me with this?

Public Function EmailLetterTest()
On Error GoTo Failed
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

Set con = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
'Get the data to be printed
rs.Open "select * from tTrainingSchedule where id=1", con

If rs.RecordCount = 0 Then
MsgBox "No data found"
Exit Function
End If

rs.MoveFirst
'************************************************* *******
'GENERATE LETTER
'Create Object for the new Word Application
Dim myWordObj As Object
Dim doc1 As Document
Set myWordObj = CreateObject("WORD.APPLICATION")
myWordObj.Visible = True



myWordObj.Documents.Add "F:\APPS\Colossus
II\Documents\TrainingConfirmationLetter.doc"
With myWordObj.Selection
.EndKey 6, 0
'.typetext Text:="Sangeeta Noby"
'.typeparagraph
myWordObj.ActiveDocument.Tables.Add
Range:=myWordObj.Selection.Range, NumRows:=1, NumColumns:=6,
DefaultTableBehavior:=2, AutoFitBehavior:=0
'.MoveRight unit:=12
.typetext Text:="Date"
.MoveRight unit:=12
.typetext Text:="Number of Participants"
.MoveRight unit:=12
.typetext Text:="Start Time"
.MoveRight unit:=12
.typetext Text:="End Time"
.MoveRight unit:=12
.typetext Text:="Estimated Amount"
.MoveRight unit:=12
.typetext Text:="Training Location"

.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("AllottedDate"))
.MoveRight unit:=12
.typetext Text:="1"
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedStartTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedEndTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("EstimatedAmount"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("TrainingLocation"))
'.Kind = wdEMail
End With


'************************************************* ***********
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
'GENERATE E-MAIL
Dim objOutlook As Outlook.Application
Dim aNamespace As NameSpace
Dim aFolder As MapiFolder
Dim aItems As Items
Dim aNewItem As Outlook.MailItem

Set objOutlook = CreateObject("OUTLOOK.APPLICATION")
Set aNamespace = objOutlook.GetNamespace("MAPI")
Set aFolder = aNamespace.GetDefaultFolder(OLFolderInbox)
Set aItems = aFolder.Items
Set aNewItem = objOutlook.CreateItem(OLMailitem)

With aNewItem
.Subject = "Testing"
.To = "
.BodyFormat = olFormatRichText 'I tried HTML and the other options does
no luk
.Body = myWordObj.Documents(1).Content
.Display
End With

Set myWordObj = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Exit Function
Failed:
HandleError Err.Description, Err.Number, Err.Source, "test:EmailLetterTest"
End Function

  #5  
Old October 3rd 06, 10:13 PM posted to microsoft.public.outlook.program_vba
Sangeeta Michael
external usenet poster
 
Posts: 5
Default How to copy the format in word document to Outlook Mail

Eric,
I cannot follow your easiest path becoz all the information in the to,
subject etc fields in the new mail is automatically generated from the
database and i have to fill them in the outlook object.
Could you give me some assistance on how i can do this using the second
method you suggested.
I am not that an expert on VBA. Could you help please?

"Eric Legault [MVP - Outlook]" wrote:

You're right, I tried - doesn't work.

The easiest way to do this is without code - in Word, choose File - Send To
- Mail Recipient. Recipients will get exactly what you see in the Word
document in the e-mail message body.

Otherwise, you'd need to build your Word document in Outlook and use Word as
the e-mail editor. You can use the Inspector.WordEditor property to get a
handle to a Word.Document object and use Word VBA in your Outlook VBA Editor
to build the document contents, and then you'll have full control
programmatically over the sending of the e-mail.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

No luck
The table comes out like this

Date
Number of Participants
Start Time
End Time
Estimated Amount
Training Location

10/1/2006
1
9:00 AM
1:00 PM
1100
3


"Eric Legault [MVP - Outlook]" wrote:

Try setting Outlook to use Word as the e-mail editor for new messages and see
if the formatting is better.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

Hi,
I am trying to develop an application that creates a word object and then
generates a letter based on the data pulled out from the database. I need to
then send this letter from Outlook.
My code executes what i want it to but my problem is
1) i am creating a new table into an existing form (This does not keep the
font of the existing form)
2) When i pull the created document into outlook, it does not keep the
formatting, neither does it display the table.
I will give the code i have used for this process
Could some one help me with this?

Public Function EmailLetterTest()
On Error GoTo Failed
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

Set con = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
'Get the data to be printed
rs.Open "select * from tTrainingSchedule where id=1", con

If rs.RecordCount = 0 Then
MsgBox "No data found"
Exit Function
End If

rs.MoveFirst
'************************************************* *******
'GENERATE LETTER
'Create Object for the new Word Application
Dim myWordObj As Object
Dim doc1 As Document
Set myWordObj = CreateObject("WORD.APPLICATION")
myWordObj.Visible = True



myWordObj.Documents.Add "F:\APPS\Colossus
II\Documents\TrainingConfirmationLetter.doc"
With myWordObj.Selection
.EndKey 6, 0
'.typetext Text:="Sangeeta Noby"
'.typeparagraph
myWordObj.ActiveDocument.Tables.Add
Range:=myWordObj.Selection.Range, NumRows:=1, NumColumns:=6,
DefaultTableBehavior:=2, AutoFitBehavior:=0
'.MoveRight unit:=12
.typetext Text:="Date"
.MoveRight unit:=12
.typetext Text:="Number of Participants"
.MoveRight unit:=12
.typetext Text:="Start Time"
.MoveRight unit:=12
.typetext Text:="End Time"
.MoveRight unit:=12
.typetext Text:="Estimated Amount"
.MoveRight unit:=12
.typetext Text:="Training Location"

.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("AllottedDate"))
.MoveRight unit:=12
.typetext Text:="1"
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedStartTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedEndTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("EstimatedAmount"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("TrainingLocation"))
'.Kind = wdEMail
End With


'************************************************* ***********
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
'GENERATE E-MAIL
Dim objOutlook As Outlook.Application
Dim aNamespace As NameSpace
Dim aFolder As MapiFolder
Dim aItems As Items
Dim aNewItem As Outlook.MailItem

Set objOutlook = CreateObject("OUTLOOK.APPLICATION")
Set aNamespace = objOutlook.GetNamespace("MAPI")
Set aFolder = aNamespace.GetDefaultFolder(OLFolderInbox)
Set aItems = aFolder.Items
Set aNewItem = objOutlook.CreateItem(OLMailitem)

With aNewItem
.Subject = "Testing"
.To = "
.BodyFormat = olFormatRichText 'I tried HTML and the other options does
no luk
.Body = myWordObj.Documents(1).Content
.Display
End With

Set myWordObj = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Exit Function
Failed:
HandleError Err.Description, Err.Number, Err.Source, "test:EmailLetterTest"
End Function

  #6  
Old October 3rd 06, 10:26 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default How to copy the format in word document to Outlook Mail

Your solution is a little complex because it involves both Word and Access,
so you'll need to do your part to migrate your code to Outlook. First of all
you'll need to enable Word as the e-mail editor in Outlook. Then your base
macro for creating the e-mail in Outlook will look like this:

Sub GenerateWordEmail
Dim objMail As Outlook.MailItem
Dim objInsp As Outlook.Inspector
Dim objWordDoc As Word.Document

Set objMail = Application.CreateItem(olMailItem)
Set objInsp = objMail.GetInspector
Set objWordDoc = objInsp.WordEditor

'Now work with the Word Document object mode via objWordDoc to automate
the creation of the content
'within the document, calling Access or whatever else you need

'Display or send when done
'objMail.Display
'objMail.Send
End Sub

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

Eric,
I cannot follow your easiest path becoz all the information in the to,
subject etc fields in the new mail is automatically generated from the
database and i have to fill them in the outlook object.
Could you give me some assistance on how i can do this using the second
method you suggested.
I am not that an expert on VBA. Could you help please?

"Eric Legault [MVP - Outlook]" wrote:

You're right, I tried - doesn't work.

The easiest way to do this is without code - in Word, choose File - Send To
- Mail Recipient. Recipients will get exactly what you see in the Word
document in the e-mail message body.

Otherwise, you'd need to build your Word document in Outlook and use Word as
the e-mail editor. You can use the Inspector.WordEditor property to get a
handle to a Word.Document object and use Word VBA in your Outlook VBA Editor
to build the document contents, and then you'll have full control
programmatically over the sending of the e-mail.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

No luck
The table comes out like this

Date
Number of Participants
Start Time
End Time
Estimated Amount
Training Location

10/1/2006
1
9:00 AM
1:00 PM
1100
3


"Eric Legault [MVP - Outlook]" wrote:

Try setting Outlook to use Word as the e-mail editor for new messages and see
if the formatting is better.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Sangeeta Michael" wrote:

Hi,
I am trying to develop an application that creates a word object and then
generates a letter based on the data pulled out from the database. I need to
then send this letter from Outlook.
My code executes what i want it to but my problem is
1) i am creating a new table into an existing form (This does not keep the
font of the existing form)
2) When i pull the created document into outlook, it does not keep the
formatting, neither does it display the table.
I will give the code i have used for this process
Could some one help me with this?

Public Function EmailLetterTest()
On Error GoTo Failed
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

Set con = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
'Get the data to be printed
rs.Open "select * from tTrainingSchedule where id=1", con

If rs.RecordCount = 0 Then
MsgBox "No data found"
Exit Function
End If

rs.MoveFirst
'************************************************* *******
'GENERATE LETTER
'Create Object for the new Word Application
Dim myWordObj As Object
Dim doc1 As Document
Set myWordObj = CreateObject("WORD.APPLICATION")
myWordObj.Visible = True



myWordObj.Documents.Add "F:\APPS\Colossus
II\Documents\TrainingConfirmationLetter.doc"
With myWordObj.Selection
.EndKey 6, 0
'.typetext Text:="Sangeeta Noby"
'.typeparagraph
myWordObj.ActiveDocument.Tables.Add
Range:=myWordObj.Selection.Range, NumRows:=1, NumColumns:=6,
DefaultTableBehavior:=2, AutoFitBehavior:=0
'.MoveRight unit:=12
.typetext Text:="Date"
.MoveRight unit:=12
.typetext Text:="Number of Participants"
.MoveRight unit:=12
.typetext Text:="Start Time"
.MoveRight unit:=12
.typetext Text:="End Time"
.MoveRight unit:=12
.typetext Text:="Estimated Amount"
.MoveRight unit:=12
.typetext Text:="Training Location"

.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("AllottedDate"))
.MoveRight unit:=12
.typetext Text:="1"
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedStartTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(Format(rs.Fields("AllottedEndTime"), "h:mm
AM/PM"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("EstimatedAmount"))
.MoveRight unit:=12
.typetext Text:=CStr(rs.Fields("TrainingLocation"))
'.Kind = wdEMail
End With


'************************************************* ***********
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
'GENERATE E-MAIL
Dim objOutlook As Outlook.Application
Dim aNamespace As NameSpace
Dim aFolder As MapiFolder
Dim aItems As Items
Dim aNewItem As Outlook.MailItem

Set objOutlook = CreateObject("OUTLOOK.APPLICATION")
Set aNamespace = objOutlook.GetNamespace("MAPI")
Set aFolder = aNamespace.GetDefaultFolder(OLFolderInbox)
Set aItems = aFolder.Items
Set aNewItem = objOutlook.CreateItem(OLMailitem)

With aNewItem
.Subject = "Testing"
.To = "
.BodyFormat = olFormatRichText 'I tried HTML and the other options does
no luk
.Body = myWordObj.Documents(1).Content
.Display
End With

Set myWordObj = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Exit Function
Failed:
HandleError Err.Description, Err.Number, Err.Source, "test:EmailLetterTest"
End Function

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I insert an outlook calender into a word document? Bob S. Outlook - Calandaring 1 September 16th 06 01:01 PM
Copy Text from Word Doc into E-mail message gumby Outlook - General Queries 8 September 13th 06 09:11 PM
How can I copy current month from calendar into a word document? Calendar Girl Outlook - Calandaring 0 September 7th 06 06:48 PM
blank Word document in Mail Merge jms00 Outlook - Using Contacts 3 May 12th 06 02:38 PM
How do I convert Outlook calendar into a Word document? Jeana Outlook - Calandaring 2 March 7th 06 04:03 PM


All times are GMT +1. The time now is 05:54 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.