TechSpot

Problem Sending Email from Word

By Themis
Mar 28, 2007
  1. OK, so here’s my problem.

    I made up a request form in Word that has quite a few macros in it to automate the request process. My planned coup d’ grace was to have a macro commanded from the file menu to allow the submitter to kick out an E-mail, with the form attached, to the approver. The E-mail arrives in the approvers Inbox but when he double-clicks the Word icon the following popup appears:

    Microsoft Office Outlook
    “The operation failed. An object could not be found”

    And the Word document does not open. I also notice that the document size indicated is much smaller than it should be if the whole document was there.

    We are using MS Office Word 2003, Microsoft Office Outlook & Windows XP.

    The code I’m using for sending the form is below.


    Sub SendMailNew()
    Dim docWif As Word.Document
    Dim sProfile As String
    Dim objSession As Object
    Dim objMessage As Object
    Dim objRecipient As Object

    sProfile = ""
    Set docWif = ActiveDocument

    Set objSession = CreateObject("mapi.session")
    objSession.Logon profileName: = sProfile

    Set objMessage = objSession.Outbox.Messages.Add
    objMessage.Subject = "Submission"

    objMessage.Text = "A new request entitled :" & ActiveDocument.Bookmarks("Title").Range _
    & ", has been submitted for consideration by " & ActiveDocument.Bookmarks("OrigSelect").Range

    objMessage.Attachments.Add docWif

    Set objRecipient = objMessage.Recipients.Add

    objRecipient.Name = "John Doe"
    objRecipient.Resolve


    objMessage.Send showDialog:=False
    MsgBox "Message is in your Outbox and will be sent shortly!"

    objSession.Logoff
    End Sub
     
  2. jobeard

    jobeard TS Ambassador Posts: 9,311   +617

    you need to implement some debug code to verify that EACH object is not empty.
    this will tell you where your code has failed.
     
  3. Themis

    Themis TS Rookie Topic Starter

    Debug code

    Can you direct me to a site or book(s) where I could learn about writing debug code. I've been unsuccessful searching for it with Google.

    Thanks.
     
Topic Status:
Not open for further replies.

Similar Topics

Add New Comment

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...