Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mulitple mail recipients in macro

Status
Not open for further replies.

jezmondo

IS-IT--Management
Aug 24, 2001
23
GB
I have a macro that will run and save reports and then e mail a user. I need this mail to be sent to more than one user but can't figure out the syntax...

I currently have:

Set objNotesSession = CreateObject("Notes.NotesSession") strMailServer = "mailserver"
strMailFile = "mail\username.nsf"


Set objNotesDB = objNotesSession.GetDatabase(strMailServer,strMailFile)
Set objDoc = objNotesDB.CreateDocument()
strNotesBody = "Hello, the reports have run" strNotesSubject = "Your eP reports have run"
objDoc.subject = strNotesSubject
objDoc.body = strNotesBody
Set objRichText = objDoc.CreateRichTextItem("NewBody")

objDoc.SendTo = "anyone@anywhere.co.uk"
Call objDoc.Send(False)

Set objNotesSession = Nothing
Set objNotesDB = Nothing
Set objDoc = Nothing
Set objRichText = Nothing
Set objAttach = Nothing

End Sub

I basically need to know how to add more names after objDoc.SendTo =

Any ideas?
 
Jezmondo,

Add in additional people to the line like this -

objDoc.SendTo ="anyone@anywhere.co.uk;2ndperson@home.co.uk"

Otherwise you can you Mailing Groups so you can add or delete recipients and not have to change the script.

See how you go!!!

Nico.
 
Thanks for this. Interesting code. I also use Notes but do not know what you do with the 'Set objAttach'in order for me to attach the .pdf or.xls.
 
Hi Reece,

If you want to attach PDF or XLS files you can use the following script which also saves the email in the sent box. The earlier scripts I used didn't do that which is a problem when logging email distribution.

See what you think.

Craig Nichols



Declare Sub SendNotesMail(Attachment As String, Recipient As String, BodyText As String, Subject As String)
Declare Sub GenerateReports(strIMRReportPath As String, strIMRReportName As String, strReportPath As String, strReportName As String, strPDFSwitch as String, strExcelSwitch as String, strPrintSwitch as String)


Sub Main()
Dim ImpApp as Object
Dim ImpRep as Object
Dim PDFPub as Object

Dim objPDF as Object
Dim strIMRReportPath
Dim strIMRReportName
Dim strReportPath
Dim strReportName
Dim strPDFSwitch
Dim strExcelSwitch
Dim strPrintSwitch
Dim BodyText
Dim Recipient
Dim Attachment
Dim Subject

' REPORT NAME'
' P&N ORDERS LESS THAN $100 '
strIMRReportPath = "J:\BI\Reports\PAN\MANAGEMENT REPORTS\"
strIMRReportName = "P&N ORDERS LESS THAN $100"
strReportPath = "U:\COGNOS REPORTS\MANAGEMENT\"
strReportName = Mid$(Date$,7,4) + Mid$(Date$,1,2) + Mid$(Date$,4,2) & " " & strIMRReportName

strPDFSwitch = "Y"
strExcelSwitch ="Y"
strPrintSwitch = "Y"
Call GenerateReports(strIMRReportPath, strIMRReportName, strReportPath, strReportName, strPDFSwitch, strExcelSwitch, strPrintSwitch)
'EMAIL ADOBE REPORT'
Recipient = "MONTHLYMANAGEMENT"
BodyText = strReportName
Attachment = strReportPath + BodyText + ".pdf"
Subject = strReportName
Call SendNotesMail(Attachment, Recipient, BodyText, Subject )


' REPORT NAME'
' OUTSTANDING SPECIAL SALES '
strIMRReportPath = "J:\BI\Reports\PAN\MANAGEMENT REPORTS\"
strIMRReportName = "OUTSTANDING SPECIAL SALES"
strReportPath = "U:\COGNOS REPORTS\MANAGEMENT\"
strReportName = Mid$(Date$,7,4) + Mid$(Date$,1,2) + Mid$(Date$,4,2) & " " & strIMRReportName

strPDFSwitch = "N"
strExcelSwitch ="Y"
strPrintSwitch = "N"
Call GenerateReports(strIMRReportPath, strIMRReportName, strReportPath, strReportName, strPDFSwitch, strExcelSwitch, strPrintSwitch)
'EMAIL ADOBE REPORT'
Recipient = "MONTHLYSPECIALS"
BodyText = strReportName
Attachment = strReportPath + BodyText + ".pdf"
Subject = strReportName
Call SendNotesMail(Attachment, Recipient, BodyText, Subject )

' REPORT NAME'
' PN8006M GRINDING WHEEL USAGE MAR '
strIMRReportPath = "J:\BI\Reports\PAN\MANAGEMENT REPORTS\"
strIMRReportName = "PN8006M GRINDING WHEEL USAGE MAR"
strReportPath = "U:\COGNOS REPORTS\MANAGEMENT\"
strReportName = Mid$(Date$,7,4) + Mid$(Date$,1,2) + Mid$(Date$,4,2) & " " & strIMRReportName

strPDFSwitch = "N"
strExcelSwitch ="Y"
strPrintSwitch = "N"
Call GenerateReports(strIMRReportPath, strIMRReportName, strReportPath, strReportName, strPDFSwitch, strExcelSwitch, strPrintSwitch)
'EMAIL ADOBE REPORT'
Recipient = "thudson@pnaust.com.au"
BodyText = strReportName
Attachment = strReportPath + BodyText + ".pdf"
Subject = strReportName
Call SendNotesMail(Attachment, Recipient, BodyText, Subject )

' REPORT NAME'
' P&N CREDITS OSBSTD '
strIMRReportPath = "J:\BI\Reports\PAN\MANAGEMENT REPORTS\"
strIMRReportName = "P&N CREDITS OSBSTD"
strReportPath = "U:\COGNOS REPORTS\MANAGEMENT\"
strReportName = Mid$(Date$,7,4) + Mid$(Date$,1,2) + Mid$(Date$,4,2) & " " & strIMRReportName

strPDFSwitch = "Y"
strExcelSwitch ="N"
strPrintSwitch = "N"
Call GenerateReports(strIMRReportPath, strIMRReportName, strReportPath, strReportName, strPDFSwitch, strExcelSwitch, strPrintSwitch)
'EMAIL ADOBE REPORT'
Recipient = "MONTHLYMANAGEMENT"
BodyText = strReportName
Attachment = strReportPath + BodyText + ".XLS"
Subject = strReportName
Call SendNotesMail(Attachment, Recipient, BodyText, Subject )


End Sub





' *** Sub to Generate ReportS in Adobe and Excel with Format ***

Sub GenerateReportS(strIMRReportPath As String, strIMRReportName As String, strReportPath As String, strReportName As String, strPDFSwitch as String, strExcelSwitch as String, strPrintSwitch as String)

Dim ImpApp as Object
Dim ImpRep as Object
Dim PDFPub as Object
Set ImpApp = CreateObject("Impromptu.Application")
ImpApp.Visible True
Set ImpRep = ImpApp.OpenReportNoExecute(strIMRReportPath + strIMRReportName + ".imr")
ImpRep.Reexecute

'ADOBE EXPORT'
if strPDFSwitch= "Y" then Set PDFPub = ImpRep.PublishPDF
if strPDFSwitch= "Y" then PDFPub.Publish strReportPath & strReportName & ".PDF"

'PRINT REPORT'
if strPrintSwitch = "Y" then ImpRep.Print

'EXCEL WITH FORMAT EXPORT'

if strExcelSwitch = "Y" then AppActivate "Impromptu - [" & strIMRReportName & ".imr]"
if strExcelSwitch = "Y" then SendKeys "%F",1
if strExcelSwitch = "Y" then SendKeys "A",1
if strExcelSwitch = "Y" then SendKeys "{TAB}",1
if strExcelSwitch = "Y" then SendKeys "{DOWN 8}",1
if strExcelSwitch = "Y" then SendKeys "{ENTER}",1
if strExcelSwitch = "Y" then SendKeys "+{TAB}",1
if strExcelSwitch = "Y" then SendKeys strReportPath & strReportName & ".XLS",1
if strExcelSwitch = "Y" then SendKeys "{ENTER}",1

'CLOSE REPORT
ImpRep.CloseReport
'CLOSE IMPROMTU'
ImpApp.Quit
Set objImpRep = Nothing
Set objImpApp = Nothing
Set objPDFPub = Nothing

End Sub



' *** Subroutine to Send Email and Attachment ***

Sub SendNotesMail(Attachment As String, Recipient As String, BodyText As String, Subject As String)
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string

UserName = Session.UserName

MailDbName = "COGNOS.nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)

If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = "REFER ATTACHMENTS *** This email has been automatically generated from the P&N Cognos Reporting System ***"
MailDoc.SAVEMESSAGEONSEND = True
'Set up the embedded object and attachment and attach it
If Attachment <> &quot;&quot; Then

Set AttachME = MailDoc.CREATERICHTEXTITEM(&quot;Attachment&quot;)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, &quot;&quot;, Attachment)
MailDoc.CREATERICHTEXTITEM (&quot;Attachment&quot;)

End If
'Send the document
MailDoc.PostedDate = Now()
'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
 
Hi Craig

Brilliant code thanks. I used most of it and it works excellent. [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top