Hello,
The code below is in a for each loop and creates an email template based on a list of storenum (locations). The recipient line creates the run time error (I believe) when there is not a person assigned to the Global Address ID (Ops_store) in Outlook.
Usually if there is someone assigned, the code will run through creating an email template for each location. If one in the list does not have someone assigned, Excel automatically closes, reopens with the error highlighted on the recipient line.
If I remove that ID from the recipient line, it seems to work 100% of the time.
My goal here is to bypass the Ops_store address if there isn’t anyone assigned to it. I tried adding an On Error line but it always chooses to by-pass the line with Ops_Store.
Any ideas how I can get around this problem?
Any help is appreciated.
Error message
Run-time-error 2147023170
Automation Error
The remote procedure call failed
The code below is in a for each loop and creates an email template based on a list of storenum (locations). The recipient line creates the run time error (I believe) when there is not a person assigned to the Global Address ID (Ops_store) in Outlook.
VBA Code:
.To = "ASM_" & storenum & "@zcompany.com" & ";" & "Ops_Store_" & storenum & ";" & EMdm & ";" & EMMApm & ";"
Usually if there is someone assigned, the code will run through creating an email template for each location. If one in the list does not have someone assigned, Excel automatically closes, reopens with the error highlighted on the recipient line.
If I remove that ID from the recipient line, it seems to work 100% of the time.
My goal here is to bypass the Ops_store address if there isn’t anyone assigned to it. I tried adding an On Error line but it always chooses to by-pass the line with Ops_Store.
Any ideas how I can get around this problem?
Any help is appreciated.
Error message
Run-time-error 2147023170
Automation Error
The remote procedure call failed
VBA Code:
Set myolapp = CreateObject("Outlook.Application")
myolapp.Session.Logon
'Open Outlook Template from Server
Set myitem = myolapp.CreateItemFromTemplate("Z:\PrepEmails\Test1.oft")
With myitem
On error GoTo 8
.To = "ASM_" & storenum & "@zcompany.com" & ";" & "Ops_Store_" & storenum & ";" & EMdm & ";" & EMMApm & ";"
8: .To = "ASM_" & storenum & "@ zcompany.com" & ";" & EMdm & ";" & EMMApm & ";"
.Recipients.ResolveAll
.DeferredDeliveryTime = EmDat & " " & #8:00:00 AM#
.Subject = "This is a test”
'.HTMLBody = Replace(myitem.HTMLBody, "dateme", Format(Inv1, "dddd, mmmm dd, yyyy"))
.Display
End With
Set myolapp = Nothing
Set myitem = Nothing
End If