Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Emailing Document with Macros
Hi,
I am trying to use the code below, which I found on this website, but I am getting an error at " Set objMessage = objSession.Outbox.Messages.Add". This is about the fourth different code I've tried to have Word email the active document as an attachment. I've managed (with help) to get it working in Excel. Why can't they work the same? Any ideas as to my error message? I am using Windows XP. Thanks for any help. Georgie Sub MapiSendMail() Dim objSession As Object Dim objMessage As Object Dim objRecipient As Object Dim sProfile As String Dim sSubjPrmpt As String Dim sTextPrmpt As String Dim sEmailPrmpt As String Dim sMsgTitle As String sProfile = "" sEmailPrmpt = "Enter valid Email Name of message recipient:" sSubjPrmpt = "Enter the subject line for this message:" sTextPrmpt = "Enter the text for this message:" sMsgTitle = "Mapi Macro Example" Set objSession = CreateObject("mapi.session") objSession.Logon profileName:=sProfile Set objMessage = objSession.Outbox.Messages.Add objMessage.Subject = InputBox(sSubjPrmpt, sMsgTitle) objMessage.Text = InputBox(sTextPrmpt, sMsgTitle) Set objRecipient = objMessage.Recipients.Add objRecipient.Name = InputBox(sEmailPrmpt, sMsgTitle) objRecipient.Resolve objMessage.Send showDialog:=True MsgBox "Message sent successfully!" objSession.Logoff End Sub |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Emailing Document with Macros
Your code works for me. What error are you getting?
"Georgie8888" wrote in message ... Hi, I am trying to use the code below, which I found on this website, but I am getting an error at " Set objMessage = objSession.Outbox.Messages.Add". This is about the fourth different code I've tried to have Word email the active document as an attachment. I've managed (with help) to get it working in Excel. Why can't they work the same? Any ideas as to my error message? I am using Windows XP. Thanks for any help. Georgie Sub MapiSendMail() Dim objSession As Object Dim objMessage As Object Dim objRecipient As Object Dim sProfile As String Dim sSubjPrmpt As String Dim sTextPrmpt As String Dim sEmailPrmpt As String Dim sMsgTitle As String sProfile = "" sEmailPrmpt = "Enter valid Email Name of message recipient:" sSubjPrmpt = "Enter the subject line for this message:" sTextPrmpt = "Enter the text for this message:" sMsgTitle = "Mapi Macro Example" Set objSession = CreateObject("mapi.session") objSession.Logon profileName:=sProfile Set objMessage = objSession.Outbox.Messages.Add objMessage.Subject = InputBox(sSubjPrmpt, sMsgTitle) objMessage.Text = InputBox(sTextPrmpt, sMsgTitle) Set objRecipient = objMessage.Recipients.Add objRecipient.Name = InputBox(sEmailPrmpt, sMsgTitle) objRecipient.Resolve objMessage.Send showDialog:=True MsgBox "Message sent successfully!" objSession.Logoff End Sub |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Emailing Document with Macros
Hi Jezebel,
After discussing the issue with a colleague, who's experienced with macros, we were able to use the one below. I had used this one in Excel and couldn't understand why it wouldn't translate to Word (with minor tweaks), turns out I didn't tick the Outlook Library Objects in VBA. This code is much simpler than the MAPI one. THanks for your help though! Sub Mail_document_Outlook() Dim OutApp As Outlook.Application Dim OutMail As Outlook.MailItem Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(olMailItem) With OutMail .To = "" .CC = "" .BCC = "" .Subject = "This is the Subject line" + ActiveDocument.Name .Body = "Hi there" .Attachments.Add ActiveDocument.FullName .Display End With Set OutMail = Nothing Set OutApp = Nothing End Sub "Jezebel" wrote: Your code works for me. What error are you getting? "Georgie8888" wrote in message ... Hi, I am trying to use the code below, which I found on this website, but I am getting an error at " Set objMessage = objSession.Outbox.Messages.Add". This is about the fourth different code I've tried to have Word email the active document as an attachment. I've managed (with help) to get it working in Excel. Why can't they work the same? Any ideas as to my error message? I am using Windows XP. Thanks for any help. Georgie Sub MapiSendMail() Dim objSession As Object Dim objMessage As Object Dim objRecipient As Object Dim sProfile As String Dim sSubjPrmpt As String Dim sTextPrmpt As String Dim sEmailPrmpt As String Dim sMsgTitle As String sProfile = "" sEmailPrmpt = "Enter valid Email Name of message recipient:" sSubjPrmpt = "Enter the subject line for this message:" sTextPrmpt = "Enter the text for this message:" sMsgTitle = "Mapi Macro Example" Set objSession = CreateObject("mapi.session") objSession.Logon profileName:=sProfile Set objMessage = objSession.Outbox.Messages.Add objMessage.Subject = InputBox(sSubjPrmpt, sMsgTitle) objMessage.Text = InputBox(sTextPrmpt, sMsgTitle) Set objRecipient = objMessage.Recipients.Add objRecipient.Name = InputBox(sEmailPrmpt, sMsgTitle) objRecipient.Resolve objMessage.Send showDialog:=True MsgBox "Message sent successfully!" objSession.Logoff End Sub |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Mail Merge Data Question | Mailmerge | |||
Macros in a document | Microsoft Word Help | |||
Macro Security | Microsoft Word Help | |||
Emailing a MS Word 2003 document. | Microsoft Word Help | |||
Document Map and Macros | Microsoft Word Help |