Automation Error - Copy folder in subject

G

Guest

I'm trying to develop a macro that will start a new email and copy a folder
name into the subject line. A friend wrote this short piece of code and I'm
not very well versed in VBA so I can't figure out why it stops. He claims it
works on his machine. Can someone help me tweak it? Do you need more
information? Thanks in advance,
Patrick

I get a run-time error "-2147023782 (8007045)':
Automation error
A dynamic link library (DLL) initialization routine failed.

Code in (General)

Public Sub Mail_Msg()
Dim FolderName As String
Dim oFolder As Outlook.MAPIFolder
Dim objOutlook As New Outlook.Application
Dim msg As Outlook.MailItem
Dim oNS As Outlook.NameSpace

Set oNS = Application.Session
Set def = oNS.PickFolder
Set oFolder = def
FolderName = oFolder.Name
Set msg = objOutlook.CreateItem(0) ***This is where it stops***
msg.Subject = FolderName
msg.Display

End Sub
 
S

Sue Mosher [MVP-Outlook]

Remove the Dim objOutlook line and replace objOutlook in your problem statement with Application.

FYI, there is a newsgroup specifically for general Outlook programming issues "down the hall" at microsoft.public.outlook.program_vba or, via web interface, at http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top