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
Re: MS Word Command button help
This is VBA stuff, not VB.Net or Classic VB
Re: MS Word Command button help
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.
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
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
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
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