Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Trying to display a new email message with inputted content from excel sheet using VBA

$
0
0

my goal is to create a VBA code that would:

1) Create/Display a new email message (Without sending it)

2) Take all the information that is already imputed in my excel sheet:

Sendto - Sheet1 - Cell - B5

CC - Sheet1 - Cell - B7

Subject - Sheet1 - Cell - B9

Body - Sheet1 - Cell - B12 & B14

The current problem that I have with the code that I created is that when I try to add strings that connect to the excel sheet they return as "0" when the email is generated:

Picture of the error

Here is my code:

Sub send_email()

    Dim outlookApp As Outlook.Application
    Dim myMail As Outlook.MailItem
    Dim Source_File As String

    Set outlookApp = New Outlook.Application
    Set myMail = outlookApp.CreateItem(olMailItem)

    myMail.To = Str(Sheet1.Cells(2, 5))
    myMail.CC = Str(Sheet1.Cells(2, 7))
    myMail.Subject = Str(Sheet1.Cells(2, 9))
    myMail.Body = Str(Sheet1.Cells(2, 12)) & Str(Sheet1.Cells(2, 14))

    myMail.Display True   

End Sub

Ideally, this would create message that has all of the information inputted from the excel sheet's cells

Image of the ideal message

I really appreciate the help!


Viewing all articles
Browse latest Browse all 88835


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>