Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Attaching doc to Email using hyperlink (Word 2000/SR1)

    We have an "online" application form created in Word 2000 and we would like to set up a hyperlink that would automatically attaches the document (after filling it out) to an E-mail message and automatically fill in the recipient that is "default" (which would be sent to us).

    Any suggestions?

    TIA

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    Don't know if hyperlink is the thing here. How about a Submit or Send button on the form? After filling out the form, user presses the button and you get a copy of it emailed as attachment?

    Do I understand correctly?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Seattle, Washington, USA
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    Yeah, I could use a button. Now, I need to figure out how to automatically insert the email address the form is supposed to be sent to. We wanted to prevent people from typing wrong Email address in the TO field.

    Brent

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    I use VBA code to do this. Are you interested in trying that approach? If so, here's the code to put in the form template. Put a command button (named cmdSubmit) on the form and in its clicked event put Call MailForm. It'll look like this:

    Sub cmdSubmit_Click()
    Call Mailform
    end sub

    (I'm over your head now, right?)

    If you're still with me, create the sub below:

    The red line is your hard-coded recipient

    <pre>Sub MailForm()
    Dim aStr As String
    Dim objOutlook As Outlook.Application
    Dim objNameSpace As Outlook.NameSpace
    Dim objOutbox As Outlook.MAPIFolder
    Dim objNewMessage As Outlook.MailItem
    Dim MsgboxText As String

    Set objOutlook = CreateObject("Outlook.Application")
    Set objNameSpace = objOutlook.GetNamespace("MAPI")
    Set objOutbox = objNameSpace.GetDefaultFolder(olFolderOutbox)
    Set objNewMessage = objOutbox.Items.Add
    With objNewMessage
    <font color=red> .To = "The Email Recipient's Name" </font color=red>
    .BCC = "Another Recipient's Name" 'Use only if you need it
    .Subject = "The Form: " & aStr
    .Body = "Any message you like"
    .Attachments.Add ActiveDocument.FullName
    .ReadReceiptRequested = True
    .Send
    End With

    MsgboxText = "The form has been submitted. Click Ok or press [Enter] to close this document."
    If MsgBox(MsgboxText, vbOKCancel, "Close Form") Then
    With ActiveDocument
    .Saved = True
    Set aTitle = Nothing
    .Close
    End With
    End If
    'End If

    Set objNewMessage = Nothing
    Set objOutbox = Nothing
    Set objNameSpace = Nothing
    Set objOutlook = Nothing

    End Sub
    </pre>


    The nice thing about this approach is the user never sees a mail message so they can't screw up anything.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    Trying to adapt your code for Word 97 (SR-2) on Windows 95 running Outlook.

    I have a Word form and inserted a MacroButton to call cmdSubmit_Click.

    This worked fine but then Mailform stalled on Dim objOutlook as Outlook.Application. The alert box says:

    "User-defined type not defined"

    Can you tell me where I am going wrong please?

    My file attached.
    Attached Files Attached Files

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    What version of Outlook do you have?

    You need a reference to the Outlook Object Library in your VBA app.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    It's Outlook 98 build 8.5.66.14.0

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    Then the library to reference is Outlook 8.0 Object Library (I think!)
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    Hi Kevin,

    Many thanks for your help; over the weekend I came across this code by Chris Rae and managed to add active doc attachement to it:

    Sub MailDoc()

    Dim myOutlook As Object
    Dim myMailItem As Object
    ' Make instance
    Set myOutlook = CreateObject("Outlook.Application")
    ' Make mail item
    Set myMailItem = myOutlook.createitem(0)
    ' Set recipient (internal mail)
    myMailItem.Recipients.Add "Solomon, David"
    myMailItem.Recipients.Add "pearce, muriele"
    myMailItem.Recipients.Add "jones, christine"
    ' Set subject
    myMailItem.Subject = "Starters & Leavers - Leakage Contractors"
    ' Set body
    myMailItem.body = "Your own message - short one! - here"
    ' Set open doc as attachement
    myMailItem.Attachments.Add ActiveDocument.FullName
    ' And send it!
    myMailItem.send
    ' Close instance
    Set myOutlook = Nothing

    End Sub

    The attachement line is probably clumsy but it works.

    I have decided to go with this one as I am not sure that I would not have to go to every computer in the company and reference Outlook.

    Once again thank you for your help and thanks to Chris Rae.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Attaching doc to Email using hyperlink (Word 2000/SR1)

    <pre>> Dim myOutlook As Object
    > Set myOutlook = CreateObject("Outlook.Application")</pre>

    Just as a footnote, this approach is called "late binding" which essentially means that the VBA engine will look up the reference information for itself in the registry at run time. While this slows down execution a bit, if the user doesn't mind an extra moment, then it's totally worthwhile. And, if you are supporting different versions of Outlook in your office, you don't have to create different templates for different versions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •