Home > Ask the Domino Experts > LotusScript Questions & Answers > Can I use LotusScript to merge cells in a Microsoft Word table?
Ask The Domino Expert: Questions & Answers
EMAIL THIS

Can I use LotusScript to merge cells in a Microsoft Word table?

Cregg Hardwick EXPERT RESPONSE FROM: Cregg Hardwick

Pose a Question
Other Domino Categories
Meet all Domino Experts
Become an Expert for this site


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


>
QUESTION POSED ON: 26 August 2008
Is there any way to merge cells in a Microsoft Word table using LotusScript?

>
In a word, yes. But this will require communication with Microsoft Word through the component object model (COM). In theory, this isn't too difficult, but you need to understand COM.

Here are some key points to keep in mind:

  • First, you are going to create an object that is a handle to Microsoft Word. Microsoft Windows will actually open Word as though you clicked on it from the start menu.
  • Next, you'll need to know what you can call using this object, because you won't receive any auto-complete hints. An easy way to find out what to call is to open Microsoft Word and create a macro. You can then look at the macro to see what it did. To do so, open a Microsoft Word document and click Tools -> Macros -> Record new macro. In practice, there's more to it than that because Visual Basic for Applications (VBA) macros often use named parameters, instead of positional parameters.
  • Recorded VBA macros include all possible parameters for most calls, even when specifying default values. This is helpful since it allows you to use less-complicated calls from LotusScript.

Here is an example of a Microsoft Word interoperability agent. My first step was to write some LotusScript code to open Microsoft Word, and then make it visible:

Dim wApp As Variant 
Set wApp = CreateObject("Word.application")
wApp.Visible = True

Note: If the Microsoft Word application isn't visible when the code terminates -- either as requested or through an error -- an instance of Word will remain in memory. To close it, you must go to the processes list in task manager. If I didn't know which type of object to request, I could have looked on the "References" tab next to the agent's code window. This allows you to browse through all the COM objects registered on your system.

I went into Microsoft Word and recorded a macro while I created a blank document containing a table. The macro included the following code:

Documents.Add Template:="Normal", 
NewTemplate:=False, DocumentType:=0
ActiveDocument.Tables.Add Range:=
Selection.Range, NumRows:=2, NumColumns:= _
5, DefaultTableBehavior:=w
dWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed

Next, I migrated the code to LotusScript. The first line opens the blank document with the default template. This template could have been omitted. I didn't include the other parameters:

Call wApp.Documents.Add("Normal")

The next line is trickier. Because I'm unfamiliar with Microsoft Word's object model, I had to guess. I'm not concerned with the specifics, so I assumed that there would be an override -- taking only the number of rows and columns. This didn't work, so I included the range parameter again. This also was unsuccessful; therefore, I searched the Web for Word COM tables.add.

My search generated a Microsoft page that described the tables.add method. This confirmed that the range parameter is required. After following the link to the range method page, I found that it takes two parameters. I used the following code, which worked, but created the 3 x 5 tables without any cell borders:

Call xlApp.ActiveDocument.Tables.
Add(xlapp.documents(1).range(0,0),3, 5)

I didn't have a Microsoft Word example handy, so I used Excel instead. This should give you a general idea on the method.

Do you have comments on this Ask the Expert Q&A? Let us know.

Related information from SearchDomino.com:

  • Tip: Create file system labels for Excel and Word mail merges
  • 10 tips in 10 minutes: Our top LotusScript tips
  • Reference Center: LotusScript tips and advice


  • Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



    RELATED CONTENT
    LotusScript
    Can you use LotusScript to read a text file attached to a Notes doc?
    Customize the principal field of outgoing email messages
    Modifying LotusScript code for date and time handling
    Use DXL utilities for advanced replication settings in Notes
    Use LotusScript to create encrypted replicas
    Write a LotusScript agent to automate file attachments
    Troubleshooting a scheduled agent not running on a Global Notes Architecture (GNA) server
    Setting up local replication of a Lotus Notes database for offline employees
    Creating a link on an HTML page to a Microsoft Word attachment in a Lotus Notes database
    LotusScript to extract and move attachments to a Lotus Notes mailbox or file folder

    LotusScript
    LotusScript finds the first occurrence of a string from the right
    Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
    Search Microsoft Active Directory with LotusScript
    Three steps to trap and handle save conflicts with LotusScript
    Troubleshoot agents by displaying LotusScript variables online
    LotusScript sorts lists alphabetically
    Run or restart Notes/Domino agents via text messages
    LotusScript code rebuilds corrupted busytime.nsf file
    Soft-code item names to facilitate LotusScript management
    LotusScript agent automates selective mail file replication

    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



    Search and Browse the Expert Answer Center
    Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
    Browse our Expert Advice



    Lotus Notes Domino on Blackberry and mobile devices
    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




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