merge variable in the heading

WayneFrank

Member
I am doing a Word merge from a Progress program. When I put a merge variable in the heading, the merge does not put a value in it. The merge variables in the body work fine.

Funny thing is, if I use the same document and run the merge just from Word, the variable in the header gets its value just fine. From the Progress program, it skips the variable int eh heading but does the variables in the body.

What can anyone tell me? Thanks

Windows 7
Word 2007
Progress 9
 
The body of a document and the header are different sections. You need to handle the header separately. If you are not familiar with the object model, I would suggest that you first enable the Macro Recorder and do manually in Word what you want your ABL code to do. Then inspect the generated VBA code in the VBE. This will give you an idea of the objects and methods you need to use in your code.

Doing this in Word 2010 I get the following:

Code:
Sub Macro1()
'
' Macro1 Macro
'
'
' Insert | Header | Edit Header results in the following code:
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

' Ctrl+A (i.e. select all) results in the following code:
    Selection.WholeStory

' F9 (i.e. update fields) results in the following code:
    Selection.Fields.Update
    
' Close Header results in the following code:
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

I think the WholeStory method of the Selection object and the Update method of the Fields collection should get you the result you're looking for. You have to select your header separately from your document body.
 
Back
Top