Home > Domino Tips > Developer > LotusScript > Manipulating the header and footer of Microsoft Word using LotusScript
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Manipulating the header and footer of Microsoft Word using LotusScript


Cregg Hardwick
11.15.2005
Rating: -4.00- (out of 5)


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


Question 5: Do you know how to manipulate the header and footer of Microsoft Word using LotusScript (i.e., get inside a header type text and get out again)?

Cregg Hardwick: You will have to use COM. Generally, you will want to record a macro in Word, then take a look at the generated code to see how to write your code. If any constants are referenced in the macro, you'll have to manually create these in your LotusScript code since Lotus won't know about these constants. Other than that, VisualBasic (VB) and LotusScript are nearly identical.

In my version of Word, you would take the following steps:

  1. Click "Tools/Macro/Record new macro" and select the default macro name in the new macro dialog.
  2. Create a header (click "View/Header and Footer" from the menu).
  3. Click the button to "Stop recording".
  4. Click
  5. "Tools/Macro/Macros," select the new macro you just created and click "Edit."
  6. Examine the generated code. If possible, simplify it by removing anything you don't need. Run the macro as needed to test.
  7. To get the values of any constants referenced in the macro, add "MsgBox format(wConstwhatever)" and run the macro. Record the values so you can define them in Notes.
  8. Copy this code and paste it into your LotusScript code.
  9. For any constants that you need, add CONST declarations using the values collected above.
  10. Add code to open the Word document and so forth:

The finished code might look something like this:

 Dim Application As Variant
 Set Application = createObject("Word.application")
 Application.visible=True  
 Call Application.activate
 Application.documents.open(Filepath of your choice) 

Const wdFieldTime=32 
' These would be VB constants that we
 have to define in our code.
 Const wdFieldDate = 31
 Const wdSeekMainDocument=0
 Const wdSeekCurrentPageHeader = 9
 With Application
  .ActiveWindow.ActivePane.View.SeekView = 
wdSeekCurrentPageHeader
  .ActiveWindow.ActivePane.View.SeekView = 
 wdSeekMainDocument
  Call .Selection.Fields.Add
(Application.Selection.Range, wdFieldTime)
  Call .Selection.Fields.Add
(Application.Selection.Range, wdFieldDate)
 End With

Record small macros so that the resulting VB code is understandable and test everything. Remember, VB uses name-value pairs to pass parameters, but LotusScript does not. VB will, however, generate the parameters in the correct order for calling without named parameters, so they are easy to convert. Also, VB code assumes the presence of the application it is running in, so in LotusScript you have to tack the application reference onto everything. Finally, LotusScript requires the "Call" keyword where VB sometimes does not. So where Word might generate the code

Selection.Fields.Add Range:=
Selection.Range, Type:=wdFieldDate

in LotusScript this translates to

 Call Application.Selection.Fields.
Add(Application.Selection.Range,wdFieldDate)

From there, just play around until you get it to do exactly what you want.

Cregg Hardwick is Collaboration Solutions Technical Lead for CenterPoint Energy in Houston. He has an MBA, a PCLP and an MCAD and focuses on collaboration and business process support applications, and has been a Notes developer since 1998. He has graciously agreed to answer some of the many questions that come in regarding LotusScript.


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   



RELATED CONTENT
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
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication
LotusScript filters and attaches files to a Notes form

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

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.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
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