DonkeyOte
MrExcel MVP
- Joined
- Sep 6, 2002
- Messages
- 9,124
Right - this is doing my head in.
Please see the below code - the aim of which is to set up the required properties in order to send an email:
Dim aOutlook As Outlook.Application, aEmail As Outlook.MailItem
Set aOutlook = GetObject(, "Outlook.Application")
If aOutlook Is Nothing Then Set aOutlook = New Outlook.Application
Set aEmail = aOutlook.CreateItem(olmailitem)
Now the above is all hunky dory when I have Outlook open. However, if I close Outlook and then try to run it I get an error - surely the If aOutlook Is Nothing line should create the Outlook Application? But my syntax fails on the previous line ("ActiveX Components can't create object")...
Dan came up with the CreateObject syntax so I tried:
Set aOutlook = CreateObject("Outlook.Application")
which gets past until I try to create the mail item:
Set aEmail = aOutlook.CreateItem(olmailitem)
which then gives me the following error:
"Internal Application Error" which implies to me that Outlook has not been created?
Can someone explain what's going on - I am clueless on this stuff.
Or better still - can someone give me some code that will check to see if Outlook is open if not create outlook - prior to me trying to set my Dims etc and creating the email.
Thanks
LASW10
The smile is wearing thin...
Please see the below code - the aim of which is to set up the required properties in order to send an email:
Dim aOutlook As Outlook.Application, aEmail As Outlook.MailItem
Set aOutlook = GetObject(, "Outlook.Application")
If aOutlook Is Nothing Then Set aOutlook = New Outlook.Application
Set aEmail = aOutlook.CreateItem(olmailitem)
Now the above is all hunky dory when I have Outlook open. However, if I close Outlook and then try to run it I get an error - surely the If aOutlook Is Nothing line should create the Outlook Application? But my syntax fails on the previous line ("ActiveX Components can't create object")...
Dan came up with the CreateObject syntax so I tried:
Set aOutlook = CreateObject("Outlook.Application")
which gets past until I try to create the mail item:
Set aEmail = aOutlook.CreateItem(olmailitem)
which then gives me the following error:
"Internal Application Error" which implies to me that Outlook has not been created?
Can someone explain what's going on - I am clueless on this stuff.
Or better still - can someone give me some code that will check to see if Outlook is open if not create outlook - prior to me trying to set my Dims etc and creating the email.
Thanks
LASW10
The smile is wearing thin...