Forum

Debug Error at .To ...
 
Notifications
Clear all

Debug Error at .To for email value

3 Posts
3 Users
0 Reactions
175 Views
(@toriharris7225)
Posts: 2
New Member
Topic starter
 

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") & ")"Debug-Error-To.jpg

 
Posted : 21/08/2024 9:49 am
(@keebellah)
Posts: 373
Reputable Member
 

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

 
Posted : 22/08/2024 1:45 am
(@debaser)
Posts: 837
Member Moderator
 

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.

 
Posted : 22/08/2024 6:20 am
Share: