PDA

View Full Version : probably a simple problem



c thompson
08-03-2010, 08:16 PM
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

JP2112
08-13-2010, 05:38 PM
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.