We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to email a doc from within word using VBA?

Sparky191
Sparky191 asked
on
Medium Priority
481 Views
Last Modified: 2012-03-24
How can I email a doc to a group from within Word using VBA?
Comment
Watch Question

Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
Oh, and to send a Document as attachment, you'll have to save it first and then add it to the mail:

   With objMail
       .Subject = "TestMail"
       .To = sRecip
       .Attachments.Add "e:\test\myfile.doc"
       .Send
   End With

Author

Commented:
OK thanks. I'll try check that out
Top Expert 2004

Commented:
Or just automate word... (which has built in emailing capabilities)

Options.SendMailAttach = True
ActiveDocument.SendMail


Author

Commented:
rosesolutions1 - umm yeah that works aswell but that doesn't give me any options to set the name, subject or any of that stuff. Maybe there is, I might not have figured out how to do it. I'd prefer not to prompt the user for anything either, as I'm trying to make what I'm doing as simple as possible for the user.  Steiner that works fine. Cheers.
Top Expert 2004

Commented:
actually, it gives all the same options - but if you have automating outlook working, then stick with that.

Author

Commented:
Whats the syntax for getting the other options?
Top Expert 2004
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
I'm using Word Xp, I have the Outlook object referenced in my project but I get the following error whe I try to use that code, rosesolutions1.

"Runtime error '430' Class does not support automation or does not support expected interface"

I has a problem with "With Application.ActiveDocument.MailEnvelope"

Top Expert 2004

Commented:
You don't need to reference the Outlook object model (or anything else) for this code to work.

I have just switched to a clean WordXP machine (which doesn't have any dev tools or other rubbish on it) and pasted in the code from above - I do get an error, but it is just that SendMail is a reserved, non-overridable term in that version. I changed the sub name to MySendMail and it ran just fine.  

I then added a ref to the OL 10 object model - just to see if that introduced the problem, and it still runs fine.

I suggest you start a nice clean instance of word, and just test this bit...

Commented:
Hi rosesolutions1,

are you sure that Outlook is not loaded during your process? I would think Word implicitly uses Outlook to create and send the mail item, as Word seems not to have the settings (POP3 etc.) necessary to do this alone.

But since Word 97 does not support this anyway, I don't have a way to be sure about this...

Greets
Steiner
Top Expert 2004

Commented:
I am not sure which version of Word introduced the mailenvelope object - but I wouldn't be at all surprised if it was 2000.

Over the last few version Microsoft have done a lot of work getting different pieces of Office to share components (removing duplication). So you are right, that the key bits of Outlook are in fact being leveraged. However, doing it this way a lot of other Outlook stuff DOESN'T get loaded, so it is 'leaner' on memory use, and more importantly doesn't involve all the disk access that starting the bigger pieces of Outlook consumes.

Author

Commented:
Thanks all
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.