Send worksheet to multiple recipients

akb110

New Member
Joined
Feb 25, 2009
Messages
5
I have to send multiple sheets to different recipients through lotus notes. through some reference got the following macro for the same. Since i am new to macro. unable to write the fully.

Request some to help in writing the same completely.

regards


<TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111 cellSpacing=0 cellPadding=4 width="100%" border=0><TBODY><TR><TD width=15 colSpan=2>Code</TD></TR><TR><TD width=15> </TD><TD>Option Explicit <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
Sub Send_Sheets_Notes_Email() <o:p></o:p>
<o:p></o:p>
'Notes parameter for attaching the Excel files. <o:p></o:p>
Const EMBED_ATTACHMENT As Long = 1454 <o:p></o:p>
<o:p></o:p>
'A folder to temporarily store the created Excel files in. <o:p></o:p>
Const stPath As String = "c:\Attachments" <o:p></o:p>
<o:p></o:p>
'The subject for the outgoing e-mails. <o:p></o:p>
Const stSubject As String = "Weekly report" <o:p></o:p>
<o:p></o:p>
'The message in the bodies of the outgoing e-mails. <o:p></o:p>
Const vaMsg As Variant = "The weekly report as per agreement." & vbCrLf & _ <o:p></o:p>
"Kind regards," & vbCrLf & _ <o:p></o:p>
"Dennis" <o:p></o:p>
<o:p></o:p>
'Variable that holds the list of recipients for each worksheet. <o:p></o:p>
Dim vaRecipients As Variant <o:p></o:p>
<o:p></o:p>
'Variable which holds each worksheet's name. <o:p></o:p>
Dim stFileName As String <o:p></o:p>
<o:p></o:p>
'Variables for Notes. <o:p></o:p>
Dim noSession As Object <o:p></o:p>
Dim noDatabase As Object <o:p></o:p>
Dim noDocument As Object <o:p></o:p>
Dim noEmbedObject As Object <o:p></o:p>
Dim noAttachment As Object <o:p></o:p>
Dim stAttachment As String <o:p></o:p>
<o:p></o:p>
'Variables for Excel. <o:p></o:p>
Dim wbBook As Workbook <o:p></o:p>
Dim wsSheet As Worksheet <o:p></o:p>
Dim lnLastRow As Long <o:p></o:p>
<o:p></o:p>
On Error GoTo Error_Handling <o:p></o:p>
<o:p></o:p>
Application.ScreenUpdating = False <o:p></o:p>
<o:p></o:p>
Set wbBook = ThisWorkbook <o:p></o:p>
<o:p></o:p>
'Loop through the collection of worksheets in the workbook. <o:p></o:p>
For Each wsSheet In wbBook.Worksheets <o:p></o:p>
With wsSheet <o:p></o:p>
'Copy the worksheet to a new workbook. <o:p></o:p>
.Copy <o:p></o:p>
'Retrieve the worksheet's name. <o:p></o:p>
stFileName = .Name <o:p></o:p>
End With <o:p></o:p>
<o:p></o:p>
'Create the full path and name of the workbook. <o:p></o:p>
stAttachment = stPath & "\" & stFileName & ".xls" <o:p></o:p>
<o:p></o:p>
'Save and close the temporarily workbook. <o:p></o:p>
With ActiveWorkbook <o:p></o:p>
.SaveAs stAttachment <o:p></o:p>
.Close <o:p></o:p>
End With <o:p></o:p>
<o:p></o:p>
'Retrieve the list of recipients. <o:p></o:p>
With wsSheet <o:p></o:p>
lnLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row <o:p></o:p>
vaRecipients = .Range("A1:A" & lnLastRow).Value <o:p></o:p>
End With <o:p></o:p>
<o:p></o:p>
'Instantiate the Lotus Notes COM's Objects. <o:p></o:p>
Set noSession = CreateObject("Notes.NotesSession") <o:p></o:p>
Set noDatabase = noSession.GETDATABASE("", "") <o:p></o:p>
<o:p></o:p>
'If Lotus Notes is not open then open the mail-part of it. <o:p></o:p>
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL <o:p></o:p>
<o:p></o:p>
'Create the e-mail and add the attachment. <o:p></o:p>
Set noDocument = noDatabase.CreateDocument <o:p></o:p>
Set noAttachment = noDocument.CreateRichTextItem("stAttachment") <o:p></o:p>
Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment) <o:p></o:p>
<o:p></o:p>
'Add values to the created e-mail main properties. <o:p></o:p>
With noDocument <o:p></o:p>
.Form = "Memo" <o:p></o:p>
.SendTo = vaRecipients <o:p></o:p>
.Subject = stSubject <o:p></o:p>
.Body = vaMsg <o:p></o:p>
.SaveMessageOnSend = True <o:p></o:p>
.PostedDate = Now() <o:p></o:p>
.Send 0, vaRecipients <o:p></o:p>
End With <o:p></o:p>
'Delete the temporarily workbook. <o:p></o:p>
Kill stAttachment <o:p></o:p>
Next wsSheet <o:p></o:p>
<o:p></o:p>
MsgBox ("The e-mails have successfully been created and distributed."), vbInformation <o:p></o:p>
<o:p></o:p>
ExitSub: <o:p></o:p>
'Release objects from memory. <o:p></o:p>
Set noEmbedObject = Nothing <o:p></o:p>
Set noAttachment = Nothing <o:p></o:p>
Set noDocument = Nothing <o:p></o:p>
Set noDatabase = Nothing <o:p></o:p>
Set noSession = Nothing <o:p></o:p>
<o:p></o:p>
Exit Sub <o:p></o:p>
<o:p></o:p>
Error_Handling: <o:p></o:p>
MsgBox "Error number: " & Err.Number & vbNewLine & _ <o:p></o:p>
"Description: " & Err.Description, vbOKOnly <o:p></o:p>
Resume ExitSub <o:p></o:p>
End Sub <o:p></o:p>
</TD></TR></TBODY></TABLE>
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
If I read the code correctly, then the recipients are defined in Column A of first sheet.

so in A1 you put first recipient in A2 second recipient etc. etc.

vaRecipients = .Range("A1:A" & lnLastRow).Value
 
Upvote 0
Which mean that I have to put recipients in coloumn A in the first sheet of the file which contains data. how do i link which sheet need to be send to each recipient.

I need to do following activity.

Sheet recipient
Sheet 1 Mr.A
Sheet 2 Mr.B
Sheet 3 Mr.C


Also could you please write code fully for me with lines that are to be deleted, which I can copy in macro. Since I do not understand macro code.

Regards
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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