Tip

Manipulating the header and footer of Microsoft Word using LotusScript

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.


This was first published in November 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

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.