Run time error - remote procedure call failed

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
610
Office Version
  1. 365
Platform
  1. Windows
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.

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
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Can't tell from that if you using late or early binding. If late, perhaps that is why it crashes. Not sure if you're saying there is a missing value that causes the error (the variable that you dropped in the other To line) or not. If so, then test for missing values and use appropriate To. It's always best to prevent a situation that causes a foreseeable error than it is to allow it to happen and try to navigate because of it.

If you're saying the value is not missing but a recipient cannot be resolved then that's a different animal - not one that I have much experience with.
 
Upvote 0
Thank you for your feedback. I am using early binding. I thought the issue was if a person wasnt assign to the global email address, the macro would fail. Now that I test it more, I see the error happens randomly even on a location that has a perons assigned. I took out the Resolve All out of the code and ran it a few times without a problem. But that also was happening before. I will test it more next week and see if that does the tirck.
 
Upvote 0
Seems to be working after removing the Resolve All command. Going to mark this as complete.
 
Upvote 0
Solution
Seems to be working after removing the Resolve All command. Going to mark this as complete.
I did post a question in the forum but no one has replied. :(


 
Upvote 0

Forum statistics

Threads
1,224,895
Messages
6,181,620
Members
453,057
Latest member
LE102024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top