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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Attaching doc to Email using hyperlink (Word 2000/SR1)

    Author
    Topic
    #357867

    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

    Viewing 0 reply threads
    Author
    Replies
    • #532574

      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?

      • #532585

        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

        • #532586

          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

          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
                  .To = "The Email Recipient's Name" 
                  .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
          

          The nice thing about this approach is the user never sees a mail message so they can’t screw up anything.

          • #535618

            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.

            • #535672

              What version of Outlook do you have?

              You need a reference to the Outlook Object Library in your VBA app.

            • #535774

              It’s Outlook 98 build 8.5.66.14.0

            • #535931

              Then the library to reference is Outlook 8.0 Object Library (I think!)

            • #536131

              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.

            • #536312
              > Dim myOutlook As Object
              > Set myOutlook = CreateObject("Outlook.Application")

              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.

    Viewing 0 reply threads
    Reply To: Attaching doc to Email using hyperlink (Word 2000/SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: