On the line "EmailItem.To = Str(Sheet4.Cells(1, 2))" when i try to run it it comes up as a mismatch error how would i fix this?
Here is the code
Sub SendEmail_Example1()
Dim EmailApp As Outlook.Application
Dim Source As String
Set EmailApp = New Outlook.Application
Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)
EmailItem.To = Str(Sheet4.Cells(1, 2))
EmailItem.CC = "marcusburr@gmail.com"
EmailItem.Subject = "Test Email From Excel VBA"
EmailItem.HTMLBody = "Hi," & vbNewLine & vbNewLine & "This is my first email from Excel" & _
vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"VBA Coder"
EmailItem.Send
End Sub
EmailItem.To = Str(Sheet4.Cells(1, 2))
Str
expects a numeric argument. Are you thinking of CStr()
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.