Home > Domino Tips > Developer > LotusScript > Create file system labels for Microsoft Excel and Word mail merges
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Create file system labels for Microsoft Excel and Word mail merges


Dan Frazer
04.15.2008
Rating: -2.58- (out of 5)


Lotus Notes, Domino, Workplace and WebSphere tips and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


This LotusScript code automatically creates file system labels for a Microsoft Excel file and a Microsoft Word (Avery label) mail merge template.
Related resources from SearchDomino.com:
Tip: Putting an end to the frustration of mail merge

Expert Advice: Mail merge with Microsoft Word and Lotus Notes

Tutorial: 30 LotusScript tips

LotusScript Reference Center

The Microsoft Excel file was generated in a separate process, as required. Instead of going through the process again to make labels, the LotusScript code uses the process as the data source for the mail merge.

The code also consolidates various Help documents on the Web including LotusScript, VBScript, DBase coding examples and other coding types. It's useful if working with the Microsoft Windows application programming interface (API).

The label template was downloaded from Avery.com. The Microsoft Word "mail merge" wizard was used to create the template from a sample Microsoft Excel input file. This template was then embedded into a Lotus Notes document and referenced through a view lookup.

The key feature in this subroutine is that it can run in the background and includes the entire spreadsheet, without having to iterate through the Microsoft Excel spreadsheet row-by-row.

Sub GenerateLabelsFromXLS
(ExcelInputFile,LabelsOutputFile,
MergeTemplateName As String)
On Error Goto errorhandler       
' This code creates labels 
from an Excel Spreadsheet.
On Error 213 Resume Next       
' The spreadsheet was 
created in the sub "GenerateFulfilmentXLS".
 
' ExcelInputFile is the location 
on the File System on this spreadsheet.
Dim MergeView As NotesView       
' LabelsOutputFile is the location 
on the File System for your merged output.
Dim MergeDoc As NotesDocument      
' MergeTemplateName is a lookup
 to an Embedded Word Merge Template.
Dim WordMailTPL As Variant  
' This will give us a handle on the 
embedded merge template
Dim wdFormLetters As Variant 
' This is a constant used by the 
MS Word application
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject

Set MergeView = db.GetView( "Label Templates" )
Set MergeDoc = MergeView.
GetDocumentByKey(MergeTemplateName,True)
Set rtitem = MergeDoc.GetFirstItem("Body")
Set object = rtitem.GetEmbeddedObject
("Microsoft Word Document")
Set WordMailTPL = object.Activate(False)   
' False is what starts Word 
up in the backgroud (I think).
WordMailTPL.Application.Visible = False   
' You might not need this, 
but this code seems to work and 
stays in hidden.
WordMailTPL.MailMerge.MainDocumentType 
= wdFormLetters
Call WordMailTPL.MailMerge.OpenDataSource
( ExcelInputFile,0,False,False,True,False,"",
"",False,"","","Entire Spreadsheet")
WordMailTPL.MailMerge.
SuppressBlankLines = True
WordMailTPL.MailMerge.Execute(True)   
' This is where the merge takes place
WordMailTPL.Application.ActiveDocument.
SaveAs(LabelsOutputFile)
WordMailTPL.Application.ActiveDocument.Close 
' This only closes the file in Word, 
but Word is still running.
WordMailTPL.Application.DisplayAlerts = True  
WordMailTPL.Application.Quit       
' This closes the Word.exe process

Set WordMailTPL = Nothing       
' Clears the handle on the object
 
 Print "Labels Completed"
 Exit Sub
 
errorhandler:
Msgbox "Error " & Err() & ": " & Error(),0+64,"Error"
WordMailTPL.DisplayAlerts = True
WordMailTPL.Quit
Set WordMailTPL = Nothing
End Sub

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip library by member Dan Frazer. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
LotusScript
Update the ACL from the Roles view with LotusScript
LotusScript agent moves tagged spam email to junk mail folder
Create a personalized greeting for Lotus Notes database users
Fail-safe rich-text validation using LotusScript
How to export Lotus Notes views to a Microsoft Excel database
Fix Lotus Notes 8.0 issues when launching Microsoft Office applications
Capture rich-text comments in Lotus Notes fields using LotusScript
Retrieve cell values from tables in a Lotus Notes rich-text field
Adding new variable-sized, multi-value fields to Lotus Notes documents
Keep the original Universal ID when copying a Lotus Notes document

LotusScript
Update the ACL from the Roles view with LotusScript
LotusScript agent moves tagged spam email to junk mail folder
Set a value in a field existing in another Lotus Notes database
Create an automatic scheduled view export in Excel
Top 10 LotusScript tips
Create a personalized greeting for Lotus Notes database users
Fail-safe rich-text validation using LotusScript
How to export Lotus Notes views to a Microsoft Excel database
Modifying LotusScript code for date and time handling
Fix Lotus Notes 8.0 issues when launching Microsoft Office applications

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsWebcastsWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts