How would I go about attaching an active document to an email? Is this even possible?
Printable View
How would I go about attaching an active document to an email? Is this even possible?
When you say "active document" do you mean that the document is open in Word?
And you want to e-mail it using Outlook (not Outlook Express)?
You do know that there is a menu option in Word to do that?
If you want to do it by code from VB, then one way is:
You need to Save As the document to a new document, then send the new document, then Save As back to the original...
(Don't forget the references needed for Word).
VB Code:
Dim Obj Dim OrigFullFile, TempFile As String Set Obj = Word.ActiveDocument If Obj.Saved = False Then Obj.Save OrigFullFile = Obj.FullName TempFile = Environ("Temp") & "\Document.DOC" Obj.SaveAs TempFile ' Now SaveAs back to the original name to unlock the temporary document Obj.SaveAs OrigFullFile
Then you can e-mail the attachment using Outlook:
VB Code:
'Reference Microsoft Outlook 9.0 Object Library (msoutl9.olb) Private Sub Email_Click() Dim olapp As New Outlook.Application Dim olMail As Outlook.MailItem Dim myAttachment As Outlook.Attachments 'Create a new mail object form the 'Outlook98 Application object Set olMail = olapp.CreateItem(olMailItem) Set myAttachment = olMail.Attachments myAttachment.Add "C:\text.txt" olMail.Subject = “Testing a send of a message” olMail.Body = "Hello, this is the body" olMail.Recipients.Add “[email protected]” olMailsend Set olMail = Nothing Set olapp = Nothing End Sub
I apologize for the lack of information. Yes, I know that this is an option in the File drop down menu but, this is actually for a form that will have a command button placed on it so that it automatically sends a copy of the active/open document/form to a group of recipients based on a field's selection.
I know. Too much information this time, right. Please forgive. I'm new to the forum.
This is the exact same thing I'm looking for help on...
I have a command button on a form in Word that is acting as a Submit button. I have it so that when it is clicked it attaches the document to an Outlook mail message, but I am looking for help to figure out to get my email address put in as the recipient address because people are going to be sending it back to me.
The code I have for the command button right now is this:
Private Sub CommandButton1_Click()
Application.Options.ButtonFieldClicks = 1
Options.SendMailAttach = True
ActiveDocument.SendMail
End Sub
Anyone help with this would be greatly appreciated.
-Joe
Here is the other thread from yesterday that is exactly the same need.
http://vbforums.com/showthread.php?t=502190