|
-
Apr 7th, 2006, 07:22 AM
#1
Thread Starter
Member
[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
-
Apr 7th, 2006, 08:44 AM
#2
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 7th, 2006, 10:03 AM
#3
Thread Starter
Member
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?
-
Apr 7th, 2006, 10:05 AM
#4
Thread Starter
Member
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.
-
Apr 7th, 2006, 10:05 AM
#5
Re: [RESOLVED] VBA Macro to save a document then email as an attachment
Why are you trying to save it as a template?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 7th, 2006, 10:17 AM
#6
Thread Starter
Member
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
-
Apr 7th, 2006, 10:37 AM
#7
Re: [RESOLVED] VBA Macro to save a document then email as an attachment
Gotcha
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|