All, I'm having trouble converting the following e-mail program.
Currently it's setup to attach the active sheet within the active book.
I need it to attach a file named book1.htm that resides in the the
following path:
L:\Elec Dept Projects\MATERIALS\TMP"
If someone could please tell me how/make the necessary changes the following code to so it will do this. I would greatly appreciate it.
Please see code:
Option Explicit
Const EMBED_ATTACHMENT As Long = 1454
Const stPath As String = "L:\Elec Dept Projects\MATERIALS\TMP"
Dim stSubject As String
'Const vaMsg As Variant = "The weekly report as per agreement." & vbCrLf & "Kind regards," & vbCrLf & "BDB"
Dim vaMsg As Variant
Const vaCopyTo As Variant = "bdb@mail.org" 'your e-mail address
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
Dim vaRecipient As Variant, vaMsg As Variant
Const stPath As String = "L:\Elec Dept Projects\MATERIALS\TMP"
stSubject = Sheets("BOM").Range("O18").Value
vaMsg = Sheets("BOM").Range("O19").Value & vbCrLf & Sheets("BOM").Range("O20").Value _
& vbCrLf & Sheets("BOM").Range("O21").Value & vbCrLf & vbCrLf & Sheets("BOM").Range("O22").Value _
& vbCrLf & (stPath & "\Book1.htm")
'Copy the active sheet to a new temporarily workbook.
With ActiveSheet
.Copy
stFileName = .Range("O2").Value & "_" & "BOM"
End With
stAttachment = stPath & "\" & stFileName & ".xls"
'With ActiveWorkbook
With vaMsg
'With Sheets("BOM").Range("A1:G30")
.SaveAs stAttachment
.Close
'End With
End With
'Create the list of recipients.
With ActiveSheet
vaRecipients = VBA.Array(.Range("O15").Value, .Range("P16").Value, .Range("P17").Value)
End With
'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
.CopyTo = vaCopyTo
.Subject = stSubject
.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
Thanks,
BDB
Bookmarks