[RESOLVED] VBA Macro to save a document then email as an attachment
Hi, is it possible to have one button on a word document that asks the user for a filename, saves the document using the filename and then emails the document as an attachment to a specific person.
If it is, could someone please explain, thanks
Re: VBA Macro to save a document then email as an attachment
Yes, if you have an email client installed on th system.
First, use the .SendMailAttach to identify that it needs to be attached and not part of the email body.
Then, invoke a SendMail method.
VB Code:
ActiveDocument.SaveAs FileName:="C:\Test.doc" 'Add more code for the saveas dialog browse
Options.SendMailAttach = True
ActiveDocument.SendMail
Re: VBA Macro to save a document then email as an attachment
Hi, thanks for the reply
I must be doing soemthing wrong, entered the code;
Private Sub Commandbutton2.Click()
SaveFileName= _
InputBox( _
"Enter a name for the letter", _
"Letter name ?")
If SaveFileName <> "" _
Then
ActiveDocument.SaveAs (SaveFileName)
Options.SendMailAttach = True
ActiveDocument.SendMail
End Sub
The document is saved as a .dot file, so when I double click on the file it loads it as Document.doc, but when I click on the button it doesn't do much, when I double click on it it loads the text above in Microsoft Visual Basic interface.
ANy ideas where I'm going wrong?
Re: VBA Macro to save a document then email as an attachment
Ignore me, macro's were set to high, sorry about that, everything now works wonderfully and your code example is just what I need, thanks again, appreciate it.
Re: [RESOLVED] VBA Macro to save a document then email as an attachment
Why are you trying to save it as a template?
Re: [RESOLVED] VBA Macro to save a document then email as an attachment
No I think you misunderstand, the document is a template, selectable by the user which when the double click on it then opens it has a document.doc file rather than the .dot, just easier than risking the user saving over the original. Thanks again for your input, now working fine, cheers
Re: [RESOLVED] VBA Macro to save a document then email as an attachment