Run macro script instead of calling the macro

J

Jeff C

I pieced together the following so that a report out of MSAccess could be
emailed in the body of an Outlook email instaed of as an attachment which is
evidently easier for Blackberry users.

Can anyone advise as to how to incorpoarte the code behind the macro instead
of having to call the macro? This would save building the macro in all the
users WORD application.

I made a couple attempts but could do it. Any help appreciated, Thank you
 
J

Jeff C

Private Sub Command5_Click()
DoCmd.OutputTo acOutputReport, "NameOfAccessReport", acFormatRTF,
"FullNameAndPathOfOutputFile"

Dim wdApp As Word.Application
Dim doc As Word.Document

Set wdApp = New Word.Application
Set doc = wdApp.Documents.Open("FullNameAndPathOfOutputFile")
wdApp.Run "NameOfMacro"
wdApp.Quit False
Set doc = Nothing
Set wdApp = Nothing

Kill ("FullNameAndPathOfOutputFile")

End Sub

Sub NameOfMacro()

Set Report = ActiveDocument.MailEnvelope.Item
Report.To = "RecipientEmailAddress"
Report.Subject = "WhatEverYouWant"
Report.Send
End Sub
 
D

Doug Robbins - Word MVP

Try:

Private Sub Command5_Click()
DoCmd.OutputTo acOutputReport, "NameOfAccessReport", acFormatRTF,
"FullNameAndPathOfOutputFile"

Dim wdApp As Word.Application
Dim doc As Word.Document
Dim Report As MailItem

Set wdApp = New Word.Application
Set doc = wdApp.Documents.Open("FullNameAndPathOfOutputFile")
Set Report = doc.MailEnvelope.Item
Report.To = "RecipientEmailAddress"
Report.Subject = "WhatEverYouWant"
Report.Send
wdApp.Quit False
Set doc = Nothing
Set wdApp = Nothing

Kill ("FullNameAndPathOfOutputFile")

End Sub



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jeff C

Works great Doug, Thank you. Is there a way to make the email come up for
editing before sending?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top