Context: |
General |
Library/Class: |
Sample Code |
Calling Word macros at specific events As Integer, Read/Write
The most common use of the Word application object is to run Word macros included in the Word template attached to the Integra profile. A typical situation to use macros is to automate the task of final document formatting.
This developer documentation, for instance, is written in hundreds of Notes documents in an Integra Developer Documentation database. An Integra profile has been created to push the documention into one ready made Word document without any further processing.
To accomplish this task, two macros had to be added to the Word template. The first one to format the Notes richtext as soon it is pushed into Word (per exported Notes document) and the second one to move the Word document header created in the template to the first page (section) after all Notes documents have been exported.
The code example below shows the calling of these macros at two different Integra events:
Const CB_INITIALISE = 3
Const CB_ACTIONONLY = 16
Const CB_BFOREXPORT = 10
Const CB_INVALID = 12
Const CB_CATEGORY = 13
Const CB_TOTAL = 14
Const CB_CONFLICT = 15
Const CB_BFORREADNOTES = 6
Const CB_BFORWRITECOM = 1
Const CB_AFTERWRITECOM = 9
Const CB_BFORCOMACTION = 5
Const CB_BFORNOTESACTION = 2
Const CB_TERMINATE = 4
select case stats.cbstatus
case CB_INITIALISE
case CB_ACTIONONLY
case CB_BFOREXPORT
case CB_INVALID
case CB_CATEGORY
case CB_TOTAL
case CB_CONFLICT
case CB_BFORREADNOTES
case CB_BFORWRITECOM
Call stats.WordAppl.Run("FormatBodyText")
case CB_AFTERWRITECOM
case CB_BFORCOMACTION
Call stats.WordAppl.Run("MoveHdr2FstPage")
case CB_BFORNOTESACTION
if not stats.savdoc is nothing then
else
end if
case CB_TERMINATE
end select
' Word Macro Example
Option Explicit
Sub MoveHdr2FstPage()
Selection.GoTo What:=wdGoToSection, _
Which:=wdGoToFirst, Count:=1, Name:=""
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Cut
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.HomeKey Unit:=wdStory
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub FormatBodyText()
Selection.GoTo What:=wdGoToBookmark, Name:="BeginOfBodyText"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(1.27)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
End Sub
|