M
MikeC
I'm running automation code in AXP that sends an email via
Outlook XP (while using Outlook Redemption). I have a PST
file and POP3/SMTP on the local machine where the code is
executing. Everything works perfectly until the "Set Btn
= ..." line (at the bottom) is executed. The below error
displays:
"Error #91 - Object variable or With block variable not
set"
Can anyone tell me what I'm doing wrong?
(I'm cross-posting
to "microsoft.public.access.modulesdaovba"
and "microsoft.public.outlook.program_vba".)
Here's the code:
===================================================
Dim SafeItem As Object
Dim oItem As Object
Dim objOL As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim Btn As Control
Dim strProfile As String
Dim strPwd As String
Dim strEmailAddrTo As String
Dim strSubject As String
Dim strMsg As String
Dim strPath As String
strEmailAddrTo = "(e-mail address removed)"
strSubject = "Subject of email"
strMsg = "MyMessage"
Set objOL = CreateObject("Outlook.Application")
Set myNameSpace = objOL.GetNamespace("MAPI")
strProfile = "My Profile Name"
strPwd = "MyPassword"
'Log into email account.
myNameSpace.Logon strProfile, strPwd, False, True
'Create an instance of Redemption.SafeMailItem
Set SafeItem = CreateObject("Redemption.SafeMailItem")
'Create a new message
Set oItem = objOL.CreateItem(0)
'set Item property
SafeItem.Item = oItem
SafeItem.Recipients.Add strEmailAddrTo
SafeItem.Recipients.ResolveAll
SafeItem.Subject = strSubject
SafeItem.Body = strMsg
SafeItem.Send
'vvvvv ERROR OCCURS ON NEXT LINE. vvvvvvvv
Set Btn = objOL.ActiveExplorer.CommandBars.FindControl
(msoControlButton, 5488)
Btn.Execute 'Emulates clicking on Send/Receive button
in Outlook XP.
===================================================
Outlook XP (while using Outlook Redemption). I have a PST
file and POP3/SMTP on the local machine where the code is
executing. Everything works perfectly until the "Set Btn
= ..." line (at the bottom) is executed. The below error
displays:
"Error #91 - Object variable or With block variable not
set"
Can anyone tell me what I'm doing wrong?
(I'm cross-posting
to "microsoft.public.access.modulesdaovba"
and "microsoft.public.outlook.program_vba".)
Here's the code:
===================================================
Dim SafeItem As Object
Dim oItem As Object
Dim objOL As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim Btn As Control
Dim strProfile As String
Dim strPwd As String
Dim strEmailAddrTo As String
Dim strSubject As String
Dim strMsg As String
Dim strPath As String
strEmailAddrTo = "(e-mail address removed)"
strSubject = "Subject of email"
strMsg = "MyMessage"
Set objOL = CreateObject("Outlook.Application")
Set myNameSpace = objOL.GetNamespace("MAPI")
strProfile = "My Profile Name"
strPwd = "MyPassword"
'Log into email account.
myNameSpace.Logon strProfile, strPwd, False, True
'Create an instance of Redemption.SafeMailItem
Set SafeItem = CreateObject("Redemption.SafeMailItem")
'Create a new message
Set oItem = objOL.CreateItem(0)
'set Item property
SafeItem.Item = oItem
SafeItem.Recipients.Add strEmailAddrTo
SafeItem.Recipients.ResolveAll
SafeItem.Subject = strSubject
SafeItem.Body = strMsg
SafeItem.Send
'vvvvv ERROR OCCURS ON NEXT LINE. vvvvvvvv
Set Btn = objOL.ActiveExplorer.CommandBars.FindControl
(msoControlButton, 5488)
Btn.Execute 'Emulates clicking on Send/Receive button
in Outlook XP.
===================================================