I have implemented the below VBA code to e-mail a single worksheet to the intended recipient (with Lotus Notes - ugh). However, it only will work on one sheet at a time. I would like to be able to select multiple sheets and have the macro run through all of them.
I'm very new to VBA, but so far I've been having a lot of fun learning! This one stumps me! Please help!
I'm very new to VBA, but so far I've been having a lot of fun learning! This one stumps me! Please help!
Code:
Option Explicit
Const EMBED_ATTACHMENT As Long = 1454
Const stPath As String = "C:\Temp"
Const stSubject As String = "Field Campaign Open Orders - "
Const vaMsg As Variant = "Please see the attached Open Field Campaign Orders." & vbCrLf & _
"Thanks," & vbCrLf & _
"Katie"
Sub Send_Active_Sheet()
Dim stFileName As String
Dim vaRecipients As Variant
Dim noSession As Object
Dim noDatabase As Object
Dim noDocument As Object
Dim noEmbedObject As Object
Dim noAttachment As Object
Dim stAttachment As String
'Copy the active sheet to a new temporarily workbook.
With ActiveSheet
.Copy
stFileName = Range("I2")
End With
stAttachment = stPath & "\" & stFileName & ".xls"
'Save and close the temporarily workbook.
With ActiveWorkbook
.SaveAs stAttachment
.Close
End With
'Create the list of recipients.
vaRecipients = Range("Q2")
'Instantiate the Lotus Notes COM's Objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
'If Lotus Notes is not open then open the mail-part of it.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the e-mail and the attachment.
Set noDocument = noDatabase.CreateDocument
Set noAttachment = noDocument.CreateRichTextItem("stAttachment")
Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = vaRecipients
.Subject = stSubject & Range("I2")
.Body = vaMsg
.SaveMessageOnSend = True
.PostedDate = Now()
.Send 0, vaRecipients
End With
'Delete the temporarily workbook.
Kill stAttachment
'Release objects from memory.
Set noEmbedObject = Nothing
Set noAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
MsgBox "The e-mail has successfully been created and distributed", vbInformation
End Sub
Last edited: