I am very much a beginner to vba.
I have an excel file set-up, so once someone enters information on a worksheet they use a push button and it attaches the file to an e-mail and populates the to/cc fields based on entries they made and some default names that always receive the file.
It works perfectly... the problem I am having is it not only attaches the active worksheet but the entire workbook which some individuals don't need to be receiving. How can I alter the code to only attach the active worksheet (with the sender's changes of course) to the e-mail and not all the pages of the workbook. I don't know how to alter my data in the upper right corner of postings but I recently started using Excel 2007. Thanks in advance! See below for the code
'Sends e-mail of X form to person in cell B5 and will cc people x and y
Sub SendMail()
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set rng = Nothing
Set rng = ActiveSheet.UsedRange
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Range("B5")
.CC = ""
.BCC = ""
.Subject = ""
.HTMLBody = ""
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
On Error GoTo 0
End Sub
Bookmarks