Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Georgie8888 Georgie8888 is offline
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Jezebel Jezebel is offline
external usenet poster
 
Posts: 1,384
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Georgie8888 Georgie8888 is offline
external usenet poster
 
Posts: 4
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail Merge Data Question Tom Bean Mailmerge 7 May 26th 06 12:02 AM
Macros in a document lionroar Microsoft Word Help 1 June 17th 05 06:42 PM
Macro Security JD Microsoft Word Help 11 April 24th 05 03:02 PM
Emailing a MS Word 2003 document. suzimcr Microsoft Word Help 0 January 12th 05 02:01 PM
Document Map and Macros montgomerymouse Microsoft Word Help 1 January 10th 05 05:49 AM


All times are GMT +1. The time now is 11:55 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"