|
-
Dec 26th, 2007, 02:36 PM
#1
Thread Starter
New Member
MS Word Command button help
Hey Everyone,
I hope someone can help with this and I apologize if there is something on here just like this, I did try searching.
I have a form in a Word Document that has a Command Button that is acting as a " Submit " button that when is clicked will attach the document to a new mail message in Outlook to be returned to me through email. I was hoping there is a way to make it so that when the button is clicked, it attaches the document as well as inserts the email address that I am reached at automatically so that the sender only has to click " SEND."
The VB code I have for the Word Document so far is this:
Private Sub CommandButton1_Click()
Application.Options.ButtonFieldClicks = 1
Options.SendMailAttach = True
ActiveDocument.SendMail
End Sub
Any help with this would be greatly appreciated. I have practically no experience working with VB.
-Joe
-
Dec 26th, 2007, 03:13 PM
#2
Re: MS Word Command button help
This is VBA stuff, not VB.Net or Classic VB
-
Dec 26th, 2007, 03:14 PM
#3
Re: MS Word Command button help
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 
-
Dec 26th, 2007, 03:19 PM
#4
Thread Starter
New Member
Re: MS Word Command button help
Oh, Sorry about that. Like I said I don't really know anything about visual basic. Thanks for pointing me in the right direction though.
-
Dec 26th, 2007, 03:41 PM
#5
Re: MS Word Command button help
I havent seem a way to populate everything using it but if you were to use Outlook code you could but its more code. If you use the ShellExecute API you can but then you get issues with translating the attachment path with proper url encoding characters.
Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWMINIMIZED As Long = 2
Private Sub CommandButton1_Click()
Application.Options.ButtonFieldClicks = 1
Options.SendMailAttach = True
ShellExecute 0&, "open", "mailto:[email protected]?subject=spam&body=blah&attach=C%3A%5CMyDoc2.docx", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
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 
-
Jun 30th, 2008, 03:18 PM
#6
New Member
Re: MS Word Command button help
When using the code provided - now the document is not attached to the email. I apologize if this is an overlook on my part, but I am very new to VB.
Thank You
-
Jul 7th, 2008, 09:25 PM
#7
Re: MS Word Command button help
The attachment file path needs to be reflective of your system and change the invalid url characters into their encoded equilivalents.
&attach=C:\MyDoc.docx
&attach=C%3A%5CMyDoc2.docx
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 
-
Jul 7th, 2008, 10:29 PM
#8
Re: MS Word Command button help
i saw a thread a few days ago that showed how to use, the routingslip property of the document to set the email address to send to using activedocument.sendmail, this is only for word prior to 2007
http://www.vbforums.com/showthread.p...94#post3272494
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|