Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to send current Word document as attachment via email

Status
Not open for further replies.

Jtorres13

Technical User
Nov 11, 2006
162
US
Hello. My users need to fill out a certain form and then they need to send it to a specific email address. They are making mistakes and sending it to the wrong person. I can't get them to follow instructions. So, I thought I'd put a macrobutton and specify the address where it needs to be sent. The macro button field code looks like this:
{MACROBUTTON FileSendMail "Double-click here to Submit"}

When I test, it creates the email and attaches the file (yay!) but there's nowhere in the field code options where to put the address to where I want to send it. So a MCROBUTTON will not work.

How do I do this with VBA? Here are some details:
1. Word 2003 SP3
2. Windows XP SP3
3. Exchange 2003
4. Outlook 2003 SP3
5. I don't want to save the document first. It will be discarded when we're done sending and I know users will not remember to delete any type of temp file created by the system.

Any ideas? I know a little bit about VBA, not much, but I can stumble my way around if I get a general idea, with a bit of examples on what to do.
 
First save the document
Code:
    SaveAs "C:\Temp\filename.doc"

then something like:
Code:
Public Sub AttachAdd()

    Dim olApp As New Outlook.Application
    Dim atts As Outlook.Attachments
    Dim newAttachment As Outlook.Attachment
    Dim newitem As Outlook.MailItem

    Set newitem = olApp.CreateItem(olMailItem)
    Set atts = newitem.Attachments
    Set newAttachment = atts.Add("C:\Temp\filename.doc", olByValue)
    
    newitem.To = "Address"
    newitem.Body = "Covering message"
    newitem.Subject = ""
    newitem.Display

    Set newAttachment = Nothing
    Set atts = Nothing
    Set newitem = Nothing

End Sub

You'll need to refrence Outlook.

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top