Outlook - emails changed based on cell value

Rbveiga

New Member
Joined
Sep 11, 2014
Messages
28
Hello,

Could you please help me?

I would like to delete sheet where it contain all the emails which should be use in my VBA.
To do it, I wrote all emails inside of VBA.

Example:

Sub email ()
Dim OutApp As Object
Dim OutMail As Object




To_Austria = "xxxx@gmail.com";"yyyyy@gmail.com;"
CC_Austria= "xxxx@gmail.com";"yyyyy@gmail.com;"
To_Belgium = "xxxx@gmail.com";"yyyyy@gmail.com;"
CC_Belgium= "xxxx@gmail.com";"yyyyy@gmail.com;"


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail


.To = "To_" & Sheet8.Cells(4, 3)
.CC = "CC_" & Sheet8.Cells(4, 3)
.BCC = ""
.Subject =""
.Body =

.Attachments.Add ActiveWorkbook.FullName
.Display 'or use .Display

End With
On Error GoTo 0


Set OutMail = Nothing
Set OutApp = Nothing
End Sub



The sheet Sheet8.Cells(4, 3) is the country which appear in the file and it can be changed manually.
When I run the macro, outlook show the text "To_Austria" and "CC_Austria" instead of emails. How could I make the VBA to take email?

regards,
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Here's an option. Though i'd just put the emails in those cells instead of "To_Austria" etc.

Code:
Sub email()
Dim OutApp As Object
Dim OutMail As Object
Dim mycountry As String
Dim myto as string
Dim mycc as string

mycountry = Sheet8.Cells(4, 3)


If mycountry = "To_Austria" Then
myto = "xxxx@gmail.com;yyyyy@gmail.com;"
mycc = "xxxx@gmail.com;yyyyy@gmail.com;"
ElseIf mycountry = "To_Belgium" Then
myto = "xxxx@gmail.com;yyyyy@gmail.com;"
mycc = "xxxx@gmail.com;yyyyy@gmail.com;"
End If


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)


On Error Resume Next
With OutMail




.To = myto
.CC = mycc
.BCC = ""
.Subject = ""
.Body =


.Attachments.Add ActiveWorkbook.FullName
.Display 'or use .Display


End With
On Error GoTo 0




Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,738
Messages
6,186,736
Members
453,369
Latest member
juliewar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top