• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Automatically CC current user for excel VBA

Elgohary11

New Member
hi there,

I have this basicvbacode and it works great. However, I'm trying to add so the current user automatically gets cc'd to the email, but I am really struggling. Can someone please help?THANKS in advance!

Code:
Sub Button1_Click()
Dim OutApp As Object
Dim OutMail As Object

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

On Error Resume Next
With OutMail
.To = "technicalsupport@cnrl.com"
.CC = .””
.BCC = ""
.Subject = "Ad Hoc Report Request"
.Body = "Request form attached."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
Last edited by a moderator:
ref to : http://www.ozgrid.com/forum/showthread.php?t=177617

Code:
Option Explicit

Sub Button1_Click()
Dim OutApp As Object, OutMail As Object, myEmail As String, xNmae As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set xNmae = OutApp.GetNamespace("MAPI")
myEmail = xNmae.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress

On Error Resume Next
With OutMail
.To = "abc@xyz"
.CC = myEmail
.BCC = ""
.Subject = "Ad Hoc Report Request"
.Body = "Request form attached."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set xNmae = Nothing
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
Back
Top