# Run time error - remote procedure call failed



## rex759 (Aug 27, 2022)

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. 


```
.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 


```
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
```


----------



## Micron (Aug 27, 2022)

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.


----------



## rex759 (Aug 27, 2022)

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.


----------



## rex759 (Aug 28, 2022)

Seems to be working after removing the Resolve All command. Going to mark this as complete.


----------



## rex759 (Dec 15, 2022)

rex759 said:


> 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. 










						PDF Copy and Paste – fails on Paste
					

Hello, I got this code from this forum to copy and paste a PDF into an Excel. Works perfectly on older versions of Windows so not sure why its not working on Windows 10. I am using Adobe Reader. The code halts on this line:  Run time error 1004 – Microsoft Excel cannot paste the data  WKS.Paste...




					www.mrexcel.com


----------

