Consulting

Results 1 to 2 of 2

Thread: probably a simple problem

  1. #1

    probably a simple problem

    I am completely new to VBA. I am trying to debug a macro written by a former co-worker. The macro runs in excel and takes data from a spreadsheet to create a MailItem in Outlook.

    The problem is that once the MailItem is created I need to modify some of the properties. I am able to modify some properties, such as 'Subject'. However, when attempting to access or assign a value to 'Body' (String type) or 'Recipients' (Outlook.Recipients type) I get the following error:

    <Application-defined or object-defined error>

    When looking at the MailItem in the debugger, the fields that I can't access show the value as '<>'. I'm not sure what this means. I thought it might mean that the object had not yet been created. I tried to use the CreateObject() method but I an error that says 'ActiveX control cannot be used to create this object'

    Here is some of the code:

    Dim objMailItem As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient

    ...

    With objMailItem
    .Subject = objTemplateSheet.Range("SelectedSubject").Value
    .Body = objTemplateSheet.Range("SelectedBody").Value
    .SentOnBehalfOfName = "..."
    End With

    ...

    Set objOutlookRecip = objMailItem.Recipients.Add("...")
    objOutlookRecip.Type = olBCC
    Set objOutlookRecip = Nothing

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Without seeing more of your code, and the order in which objects and properties are called, it's hard to tell why the error is occurring.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

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