Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15564

Regarding sending email using VBA

$
0
0
I am learning and very new into this field, so I do not have full understanding on everything...but I would like to ask a couple of questions to whom may concern.

1. When I'm trying to send email using outlook, there will be a pop up regarding there is an attachment in the email, so I have click "ok" every time there is a pop up. And I am trying to get rid of the pop up.
SendKeys "{TAB}{ENTER}", True
I already added this code into data, which I can already send out 1 email without the pop up. However the pop up still occur after the 1st email. Is there anyway to solve this?

2. There are 2 emails in Outlook, one for private use and one for public use, and I would like to use the public email to send out email. However I do not know how to specify on only using only the second public email using VBA. I already looked through a lot of information and I still cannot achieve what I want.

Here is the codes I wrote. I hope anyone who may concern could help me.

Option Explicit

Sub Send_email_fromexcel()
Dim edress As String
Dim subj As String
Dim message As String
Dim filename As String
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myAttachments As Object
Dim path As String
Dim lastrow As Integer
Dim attachment As String
Dim x As Integer
x = 2

Application.DisplayAlerts = False
Application.SendKeys "TabEnter", False
Application.DisplayAlerts = True

Do While Sheet1.Cells(x, 1) <> ""

Set outlookapp = CreateObject("Outlook.Application")
Set outlookmailitem = outlookapp.createitem(0)
Set myAttachments = outlookmailitem.Attachments
path = "C:\Users\lo\Desktop\123.pdf"
edress = Sheet1.Cells(x, 1)

subj = Sheet1.Cells(x, 2)
attachment = path + filename
outlookmailitem.To = edress
outlookmailitem.cc = ""
outlookmailitem.bcc = ""
outlookmailitem.Subject = subj
outlookmailitem.body = Sheet1.Cells(x, 3)
myAttachments.Add (attachment)
outlookmailitem.display
SendKeys "{TAB}{ENTER}", True
outlookmailitem.send

lastrow = lastrow + 1
edress = ""
x = x + 1
Loop

Set outlookapp = Nothing
Set outlookmailitem = Nothing

End Sub

Viewing all articles
Browse latest Browse all 15564

Trending Articles



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