'Mail merge script by Sacha Chua (email@example.com) Dim ws As NotesUIWorkspace Set ws = New NotesUIWorkspace Dim sendTypes(1) As String Dim sendValue As String Dim errorCount As Integer errorCount = 0 sendTypes(0) = &quot;Draft messages without sending&quot; sendTypes(1) = &quot;Send messages&quot; sendValue = ws.Prompt(PROMPT_OKCANCELLIST, &quot;Sending options&quot;, &quot;What would you like to do?&quot;, &quot;&quot;, sendTypes) If (sendValue = &quot;&quot;) Then Exit Sub End If Dim fileName As String Dim strXLFilename As String 'Prompt for the filename - should be a Microsoft Excel file with columns, where the first row of each column 'is a token that will be used when replacing text in the body of the message 'Special tokens: [to], [cc], [subject] set the appropriate fields 'Make sure the first column does not have any blank cells fileName$ = ws.Prompt(12, &quot;Select file&quot;, &quot;3&quot;) If fileName$ = &quot;&quot; Then Exit Sub 'Cancel was pressed End If strXLFilename = fileName$ Dim s As New NotesSession Dim uidoc As NotesUIDocument Dim partno As String Dim db As NotesDatabase Dim view As NotesView Dim doc As NotesDocument Dim collection As NotesDocumentCollection Dim memo As NotesDocument Dim body As NotesRichTextItem Dim newBody As NotesRichTextItem Dim range As NotesRichTextRange Dim count As Integer Set db = s.CurrentDatabase Set collection = db.UnprocessedDocuments Set memo = collection.getFirstDocument() Dim varXLFile As Variant 'Get data from the spreadsheet Set varXLFile = CreateObject(&quot;Excel.Application&quot;) varXLFile.Visible = False Dim varXLWorkbook As Variant Set varXLWorkbook = Nothing varXLFile.Workbooks.Open strXLFilename Set varXLWorkbook = varXLFile.ActiveWorkbook Dim varXLSheet As Variant Set varXLSheet = varXLWorkbook.ActiveSheet Dim lngRow As Integer Dim columnNo As Integer Dim token As String Dim value As String lngRow = 2 Dim maildoc As NotesDocument While (Not (varXLSheet.Cells(lngRow, 1).Value = &quot;&quot;)) 'Fill in the template Dim subject As String subject = memo.Subject(0) Set body = memo.GetFirstItem(&quot;Body&quot;) 'Compose message Set maildoc = New NotesDocument(db) Set maildoc= db.CreateDocument() maildoc.Form = &quot;Memo&quot; maildoc.Subject = subject Set newBody = maildoc.CreateRichTextItem(&quot;Body&quot;) Call newBody.appendRTItem(body) Set range = newBody.CreateRange 'Count the number of fields 'Look up tokens from the column headings and replace them columnNo = 1 While Not(varXLSheet.Cells(1, columnNo).Value = &quot;&quot;) token = varXLSheet.Cells(1, columnNo).Value value = varXLSheet.Cells(lngRow, columnNo).Value count = range.FindAndReplace(token, value, 16) If (token = &quot;[to]&quot;) Then maildoc.SendTo = value End If If (token = &quot;[cc]&quot;) Then maildoc.CopyTo = Split(value, &quot;,&quot;) End If If (token = &quot;[subject]&quot;) Then maildoc.Subject = value End If columnNo = columnNo + 1 Wend On Error Goto save If (sendValue = sendTypes(0)) Then Call maildoc.Save(True, False) Else maildoc.SaveMessageOnSend = True maildoc.PostedDate = Now() Call maildoc.Send(False) Call maildoc.Save(True, True) End If Goto nextrow save: Messagebox(&quot;Error processing &quot; + maildoc.sendTo) errorCount = errorCount + 1 Resume Next nextrow: lngRow = lngRow + 1 Wend If (sendValue = sendTypes(0)) Then Msgbox &quot;Drafted &quot; & (lngRow - errorCount - 2) & &quot; message(s). Errors: &quot; & errorCount Else Msgbox &quot;Sent &quot; & (lngRow - errorCount - 2) & &quot; message(s). Errors: &quot; & errorCount End If Call varXLFile.Quit
Lotus notes mail merge create and run agent
Lotus Notes Mail Merge Tool Instructions for Installation and Use Eric Weinberg August 2010 **Special Thanks to Sacha Chua for writing the code and making Mail Merge in Lotus Notes possible!**
Lotus Notes Mail Merge Installation: Create Agent Create Agent In order to create the agent, you need to have this presentation open (not a hard copy) so you can go into the notes view and copy and paste text.
Lotus Notes Mail Merge Installation: Create Agent 1. While in your mail view, click Create > Agent which will open the IBM Lotus Domino Designer and create a blank agent for you to work with.
Lotus Notes Mail Merge Installation: Create Agent 2. Choose and enter a Name for the agent, such as “Mail Merge” and then close this dialog box.
Lotus Notes Mail Merge Installation: Create Agent 3. Select (Declarations) on left, and enter this text on the right: %INCLUDE "lsconst.lss" 4. Select Initialize on left, and enter the text that is included in the Notes to this chart on the line in between Sub Initialize and End Sub on right: 5. Save your changes and close the domino designer. To see the notes, go to View > Page > Notes View After step 5, you have successfully created the Agent.
Lotus Notes Mail Merge Installation: Run Agent Run Agent In order to run the agent, you need to have created a stationery (or a drafted note) and an excel file that is already set up with the data you want to merge. This part of the deck provides examples of both that are easily imitable.
Lotus Notes Mail Merge Installation: Run Agent 6. On the left side, scroll down to Tools > Stationery. Select a pre-set stationery created specifically for the task at hand. **Stationery Example**
Lotus Notes Mail Merge Installation: Run Agent 7. At the top, click Actions > Mail Merge 8. Select your sending option Select OK Choose your source file, and voila! **It's a good idea to select “Draft messages without sending,” test with a small, test spreadsheet, and check the results before sending messages out.**
Lotus Notes Mail Merge Application: Excel Example This example on chart 5 would require an excel spreadsheet that looks like this to run correctly: In the stationery that you create, any text [inside square brackets] will be replaced by the values in your excel spreadsheet in those columns. You can also use [to]; [cc]; [bcc]; and [subject]. One note will be generated per row in the excel spreadsheet until there is a blank line. **Required Excel Spreadsheet Example**
Lotus Notes Mail Merge Application: Additional Tips <ul><li>The mail merge agent can be utilized in a number of ways. The previous example highlighted the basics of how it works. Here are a few tips and ideas: </li></ul><ul><li>To have more than one recipient or more than one person on copy, use a “,” </li></ul><ul><ul><li>If you have data with the e-mail addresses in separate cells, “CONCATENATE” can help =CONCATENATE(Cell1,“ , ”,Cell2) </li></ul></ul><ul><li>Creatively applying functions such as VLOOKUP, TRIM, PROPER, and IF can also help transform a spreadsheet or data you already have into a format that is “mail merge friendly.” </li></ul><ul><li>The text that is fed into the e-mail can be as little as one character or as big as an entire paragraph. </li></ul><ul><li>Setting up a stationery for the task at hand is simple and straightforward; ensuring the spreadsheet is “mail merge friendly” can be complex and require more advanced manipulation of the data using some of the functions listed above and more. </li></ul><ul><ul><li>Start small and simple to familiarize yourself with the tool. </li></ul></ul>