Method 'To' of object '_MailItem' failed

aleksa02

New Member
Joined
Feb 8, 2023
Messages
2
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. MacOS
Hello,

I have this code in VBA for sending invoices via outlook:
Sub EmailAsPDF()

Dim EApp As Object
Set EApp = CreateObject("Outlook.Application")

Dim EItem As Object
Set EItem = EApp.CreateItem(0)

Dim invno As Long
Dim custname As String
Dim amd As Currency
Dim dt_issue As Date
Dim path As String
Dim fname As String

invno = Range("F4")
custname = Range("A10")
amt = Range("C19")
dt_issue = Range("F3")
path = "C:\Users\User\Desktop\Fakture\"
fname = invno & " - " & custname

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, IgnorePrintAreas:=False, Filename:=path & fname

With EItem
.To = Range("A12")
.Subject = "Faktura broj: " & invno
.Body = "Faktura se nalazi u prilogu."
.Attachments.Add (path & fname & ".pdf")
.Display

End With

End Sub

It works perfectly fine on one PC and on the other it shows an error and I have no idea why.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
The problem is for some reason with the Range command, since it's working without it
 
Upvote 0

Forum statistics

Threads
1,215,382
Messages
6,124,618
Members
449,175
Latest member
Anniewonder

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