COACHMAN99
asked on
Outlook automation
Hi All,
I usually use redemption for this purpose but in this case it isn't an option.
I'm using late binding for compatibility.
When the code below runs on a non-Exchange platform it works great. It fails on the last line of the code below when using Exchange. (trying to add a recipient prior to resolving (for the purpose of add CCs))
The recipient is unknown to the system at this stage (not in contacts etc)
The error is Error 287, Application-defined or object-defined error
Does one use different libraries/code when using Outlook/Exchange?
thanks
Function SendEmail(RecipEmail As String, Subject As String, BBody As String, cc1 As String) As Boolean
On Error GoTo err_SendEmail
Dim olApp As Object
Dim olNS As Object
Dim olRecip As Object
Dim oItem As Object
' Set olApp = CreateObject("Outlook.Appl ication")
' Set olNS = CreateObject("Outlook.Name space")
Dim tInterval As Integer, signature As String
Dim i, MyFile, MyFile2, SentItemsCounter, CoverLetter, tmpEmail, ErrorLine As Long
If RecipEmail <> "" Then
SentItemsCounter = 0
SendEmail = False
Set olApp = CreateObject("Outlook.Appl ication")
Set olNS = olApp.GetNamespace("MAPI")
Set olRecip = olApp.CreateItem(olRecipie nt)
olNS.Logon
Set oItem = olApp.CreateItem(0) 'Create a new message
Set olRecip = oItem.Recipients.Add(Recip Email)
I usually use redemption for this purpose but in this case it isn't an option.
I'm using late binding for compatibility.
When the code below runs on a non-Exchange platform it works great. It fails on the last line of the code below when using Exchange. (trying to add a recipient prior to resolving (for the purpose of add CCs))
The recipient is unknown to the system at this stage (not in contacts etc)
The error is Error 287, Application-defined or object-defined error
Does one use different libraries/code when using Outlook/Exchange?
thanks
Function SendEmail(RecipEmail As String, Subject As String, BBody As String, cc1 As String) As Boolean
On Error GoTo err_SendEmail
Dim olApp As Object
Dim olNS As Object
Dim olRecip As Object
Dim oItem As Object
' Set olApp = CreateObject("Outlook.Appl
' Set olNS = CreateObject("Outlook.Name
Dim tInterval As Integer, signature As String
Dim i, MyFile, MyFile2, SentItemsCounter, CoverLetter, tmpEmail, ErrorLine As Long
If RecipEmail <> "" Then
SentItemsCounter = 0
SendEmail = False
Set olApp = CreateObject("Outlook.Appl
Set olNS = olApp.GetNamespace("MAPI")
Set olRecip = olApp.CreateItem(olRecipie
olNS.Logon
Set oItem = olApp.CreateItem(0) 'Create a new message
Set olRecip = oItem.Recipients.Add(Recip
ASKER
Thanks Jeff. (any feedback/comment on this is welcome). In this case most of those vars aren't used (copied code form elsewhere) but I fixed it anyway (and no improvement :-().
The fact that this code works 100% of the time in a situation where Exchange isn't involved, and fails 100% of the time when it is is a pointer to the problem.
The fact that this code works 100% of the time in a situation where Exchange isn't involved, and fails 100% of the time when it is is a pointer to the problem.
oK, so lets wait for an Outlook expert to chime in.
you can also add the Exchange zone to this Q.
you can also add the Exchange zone to this Q.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK,
Great,
you should now accept your own post as the solution so others can benefit.
;-)
JeffCoachman
Great,
you should now accept your own post as the solution so others can benefit.
;-)
JeffCoachman
ASKER
Apparently (when the Outlook security options (Trust Center Programmatic Access) are set, and a valid anti-virus application exists) the standard security messages are NOT displayed but parts of the object model are disabled. e.g. the following code fails on 'signature = .Body', not '.to'. If the offending line is removed all is well.
When you do this:
...only "ErrorLine " will actually be declared as a Long datatype, ...all of the preceding variable will be "Variant" datatypes
As variants the code takes longer to "Resolve" these variables, ...possibly causing other issues as well.
See here: http://www.cpearson.com/excel/DeclaringVariables.aspx
JeffCoachman