Send WorkSHEET as Email Attachment via Excel - LOTUS Notes

BuzzOffSweetheart

New Member
Joined
Feb 27, 2009
Messages
18
I need help putting a macro button on an individual worksheet so the user can click a big easy button and a new email will pop up in Lotus notes with the worksheet attached for them to input the address and then send the worksheet..

Any one know if I can do this or how I go about to accomplish this?

I prefer to:
Send individual worksheets only
The ability to input the email address is the new composition email in LOTUS Notes

Thanks in advance!
 

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"
Thank you for the quick reply and that link!! :)

I saw something similiar but that looks like I can only send the email with a predefined email body/subject and a predefined email address..

Are you familiar with any way to do it without having all the predefined parameters.. Like not actually sending the email, just getting to the step where you would hit send that way you can easily manually input the email addy in the individual email before sending?

Thanks, again!
 
Upvote 0
You could do something like this to prompt for the e-mail addresses - changed line in red:

Rich (BB code):
Const EMBED_ATTACHMENT As Long = 1454
Const stPath As String = "c:\Attachments"
Const stSubject As String = "Weekly report"
Const vaMsg As Variant = "The weekly report as per agreement." & vbCrLf & _
                                          "Kind regards," & vbCrLf & _
                                           "Dennis"
Const vaCopyTo As Variant = "name@mail.com"
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("A1").Value
  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 = Split(InputBox("Enter list of addresses separated with commas"), ",")
  '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
 
Upvote 0
Thank you so much for the reply VoG!!

Please forgive me, as I'm new to VB...

But I keep getting a Compile error.. "Expected End Sub".

Here is my code:
Code:
Private Sub CommandButton1_Click()
Const EMBED_ATTACHMENT As Long = 1454
Const stPath As String = "c:\Attachments"
Const stSubject As String = "Weekly report"
Const vaMsg As Variant = "The weekly report as per agreement." & vbCrLf & _
                                          "Kind regards," & vbCrLf & _
                                           "Dennis"
Const vaCopyTo As Variant = "[EMAIL="name@mail.com"]name@mail.com[/EMAIL]"
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("A1").Value
  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 = Split(InputBox("Enter list of addresses separated with commas"), ",")
  '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
 
Upvote 0
Ok.. I figured that out..

Now I'm getting an error...

"Run Time Error '1004' - Method 'SaveAs' of object'_Workbook' failed"

Here is my code... Problem is in red.

Rich (BB code):
Const EMBED_ATTACHMENT As Long = 1454
Const stPath As String = "c:\Attachments"
Const stSubject As String = "Materials Management Work Hour Estimate"
Const vaMsg As Variant = "Materials Management Work Hour Estimate." & vbCrLf & _
                                          "Kind regards," & vbCrLf & _
                                           "Bobby"
Const vaCopyTo As Variant = "mail@mail.com"
 
Sub CommandButton1_Click()
  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("A1").Value
  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 = Split(InputBox("Enter list of addresses separated with commas"), ",")
  '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, Bobby!!", vbInformation
End Sub

Any Ideas?
 
Upvote 0
Do you have this folder?

c:\Attachments

If not, you need to create it or change

Rich (BB code):
Const stPath As String = "c:\Attachments"

to a folder that you do have.
 
Upvote 0
Thanks, VoG..

I tested the original Code.. It fails at the same point!


Code:
  'Save and close the temporarily workbook.

  With ActiveWorkbook

    .SaveAs stAttachment

    .Close

  End With

It goes as far as copying the individual worksheet into a new workbook, but thats as far as it gets before the error..

I triple checked the directory again, also.

:eek:
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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