I wrote VBA to email a pdf document to a list of people from a template. When I run the macros to send the emails I get a debug error for the .To email address. I even have an email address in this cell. The emails still send, but how can I get rid of this debug error? Below is a screenshot of the error and the code I used.
Dim EApp As Object
Set EApp = CreateObject("Outlook.Application")
Dim EItem As Object
Set EItem = EApp.CreateItem(0)
With EItem
reportname = Range("A4")
.SentOnBehalfOfName = "[email protected]"
.To = ThisWorkbook.Sheets("DelinquencyTemplate").Range("D10").Value
.CC = ThisWorkbook.Sheets("DelinquencyTemplate").Range("D26").Value
.BCC = ThisWorkbook.Sheets("DelinquencyTemplate").Range("H26").Value
.Subject = reportname & " " & "(" & Format(Date, "mm-d-yy") & ")"
Hi,
No Excel version mentioned, but that's probably no issue here.
One thing you could try is to use .Text instead o .Value.
If the error persists but you still get the error then I would declare a variable like receiver before The Dim EApp As Object statement
Dim receiver As String
receiver = ThisWorkbook.Sheets("DelinquencyTemplate").Range("D10").Text
and replace .To = receiver and maybe do this for all statements referring to Thisworkbook
The code shown in your picture is not the same as the code in your post. The code in the post properly uses a fully qualified range (you specified the workbook and worksheet) whereas the code in your error picture just assumes the active sheet or, if the code is in a worksheet code module, that worksheet specifically regardless of which sheet is active.