Outlook 2007 macro problem using VBA

I just switched to Outlook 2007, and am having all sorts of problems with macros that use Visual Basic for Applications, referencing the Outlook 12.0 Object Library. For example, I created a simple macro directly in Outlook and VBA that creates an e-mail message with the subject ""Hello World". The body of the macro is:

Sub HelloWorldMessage()
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Hello World!"
msg.Display
Set msg = Nothing
End Sub

When I take the five lines of code, paste them into a a NaturallySpeaking macro, with the Outlook 12.0 Object Library referenced, and run the macro, it runs, but gives me an error message in line 6, Description: (10090) ActiveX Automation error. 'Incorrect function.'_

I can't figure out what is causing these problems. I should say that I've only switched to Outlook 2007, and not the entire Office 2007 suite. I know that Outlook 2007 uses a Word Editor, so I've tried adding a reference to the Word 12.0 Object Library, but that doesn't solve the problem.

Suggestions welcomed, as well as any sample outlook 2007 macros using VBA.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Matt, the following code

Matt,

the following code works for me, after setting reference to the Outlook 12.0 library:

Sub Main
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Hello World!"
msg.Display
Set msg = Nothing
End Sub

Rüdiger

rwilke wrote: Matt, the

rwilke wrote:

Matt,

the following code works for me, after setting reference to the Outlook 12.0 library:

Sub Main
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Hello World!"
msg.Display
Set msg = Nothing
End Sub

Rüdiger

Thanks, Rüdiger. Interestingly, I still get the error message, even though I am using exactly the same code and the same reference. Are you using all of Office 2007 or just Outlook 2007?

Matt, this might be it. I

Matt,

this might be it. I have all of Office 2007 installed, and, not knowing whether this is related to this, but under Office 2007 Tools, I can find "Digital certifikate for VBA projects".

Rüdiger

certificates

I'm able to add a certificate in Outlook, so I don't think that's it. It's very odd.

I found an alternative

This code works:

Dim msg As MailItem
Dim inspector as inspector
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Hello World!"
Set inspector = msg.GetInspector
inspector.Display
Set msg = Nothing

Doesn't explain why the first method works in Outlook, but not DNS, however.

Matt Chambers wrote: This

Matt Chambers wrote:

This code works:

Dim msg As MailItem
Dim inspector as inspector
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Hello World!"
Set inspector = msg.GetInspector
inspector.Display
Set msg = Nothing

Doesn't explain why the first method works in Outlook, but not DNS, however.

Matt,

the above code also works for me. I have just tested it.

Rüdiger

Thanks for checking

I have no idea why the first piece of code works in Outlook, but not DNS, on my installation, but I'll work with the second and go from there. I've found some other code examples for Outlook 2007, and am slowly rewriting my macros as time permits.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Syndicate content