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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help to trying to email a word document 1

Status
Not open for further replies.

basictypeuser

Technical User
Jun 16, 2004
17
0
0
US
Hope someone can help.

I have created a word document. And within the document I created a button to attach the current document and send it as an email. For some reason it only emails the attachment as a link and not an actual attachment. Here is the code used to send the message.

Public Sub CommandButton2_Click()

'Save the completed document.
ChangeFileOpenDirectory "C:\Temp\"
ActiveDocument.SaveAs FileName:="Camera_Maint_Support.doc", FileFormat:=wdFormatDocument, AddToRecentFiles:=True

'Create the reference to Outlook
Set appOutlook = CreateObject("Outlook.Application")
Set itmMail = appOutlook.CreateItem(olMailItem)

'Populate the mail and send
With itmMail
.To = "myaddress@net.net"
.Subject = "Maintenance Support Request"
.HTMLBody = "Service Request - Please respond to the individual listed on the Maintenance Support Request form"
.Attachments.Add "C:\Temp\Camera_Maint_Support.doc", olByValue, , "Your Document"
.Send
End With

'Close the mail objects
'Set itmMail = Nothing
'Set appOutlook = Nothing

'Close the document
'ActiveDocument.Close False

End Sub
 
Tip: use the Option Explicit instruction

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
WinBlowsME,

Thanks for your help. Works very well. I am still trying to figure out how to close word. Still remains in task manager.
 
What about the Quit method of the Word.Application object ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,

I tried that as well. Here is what I trying to create. I am confused on how to close word. My document closes but word still exists. Any ideas would be appreciated.


'Save the completed document.
ChangeFileOpenDirectory "C:\Temp\"
ActiveDocument.SaveAs FileName:="Video_Support.doc", FileFormat:=wdFormatDocument, AddToRecentFiles:=True

'Create the reference to Outlook
Set appOutlook = CreateObject("Outlook.Application")
Set itmMail = appOutlook.CreateItem(olMailItem)

'Populate the mail and send
With itmMail
.To = "myaddress@net.net"
.Subject = "OCTA Video Support Request"
.HTMLBody = "OCTA Video Service Request - Please respond to the individual listed on Video Support Request Form"
.Attachments.Add "C:\Temp\Video_Support.doc", 1, , "Your Document"
.Send
End With

'Close the mail objects
Set itmMail = Nothing
Set appOutlook = Nothing

'Close the document
ActiveDocument.Close False

WScript.Quit (0)
oWord.Application Quit

End Sub
 
What are WScript and oWord ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PH's suggestion on Optioin Explicit would be good. Also, when you post code it is helpful to state as fully as possible what is going on.

Frok reading the original post, it sounded like this was being done from Word. Yet the last post is looking like you are doing from another application, and making an instance of Word.

Which is it? And going along with PH...what is WScript and oWord?



faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top