Results 1 to 5 of 5

Thread: Email activedocument as attachment to Outlook

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    2

    Question Email activedocument as attachment to Outlook

    How would I go about attaching an active document to an email? Is this even possible?

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    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:
    1. Dim Obj
    2. Dim OrigFullFile, TempFile As String
    3.     Set Obj = Word.ActiveDocument
    4.     If Obj.Saved = False Then Obj.Save
    5.     OrigFullFile = Obj.FullName
    6.     TempFile = Environ("Temp") & "\Document.DOC"
    7.     Obj.SaveAs TempFile
    8. ' Now SaveAs back to the original name to unlock the temporary document
    9.     Obj.SaveAs OrigFullFile

    Then you can e-mail the attachment using Outlook:
    VB Code:
    1. 'Reference Microsoft Outlook 9.0 Object Library (msoutl9.olb)
    2. Private Sub Email_Click()
    3.         Dim olapp As New Outlook.Application
    4.         Dim olMail As Outlook.MailItem
    5.         Dim myAttachment As Outlook.Attachments
    6.  
    7.         'Create a new mail object form the
    8.         'Outlook98 Application object
    9.         Set olMail = olapp.CreateItem(olMailItem)
    10.         Set myAttachment = olMail.Attachments
    11.        
    12.         myAttachment.Add "C:\text.txt"
    13.      olMail.Subject = “Testing a send of a message”
    14.         olMail.Body = "Hello, this is the body"
    15.      olMail.Recipients.Add “[email protected]
    16.         olMailsend
    17.  
    18.         Set olMail = Nothing
    19.         Set olapp = Nothing
    20. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    2

    Lightbulb Thank you...

    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.

  4. #4
    New Member
    Join Date
    Dec 2007
    Posts
    5

    Re: Email activedocument as attachment to Outlook

    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

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Email activedocument as attachment to Outlook

    Here is the other thread from yesterday that is exactly the same need.
    http://vbforums.com/showthread.php?t=502190
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width