MSWord Macro Examples
Note: The following macro examples use the older MSDWord script language and not the current VBA. If you are creating Winhelp files from scratch then you are most likely using an older version of MSWord as as you authoring tool.
The following simple example inserts a browse footnote:
Sub MAIN
InsertFootnote .Reference = "+", .NoteType = 0
End Sub
A more useful example is Paul A. O'Rear's GetContextStrings macro. It will compile a list of context strings from your *rtf document that can be used in the [MAP] section of the project file. When you run it, make sure Word is in "normal" view mode.
Sub MAIN
'GetContextStrings - Macro for extracting a list of
context strings 'from a document formatted for help.
'Paul A. O'Rear - Helpful Solutions, 7/97
'Create a variable storing the name of the source document.
srcDoc$ = WindowName$()
'Create a new document and save it with the name "contexts.doc" and 'store the
name in a variable.
FileNew
FileSaveAs .Name = "contexts.doc"
ctxDoc$ = WindowName$()
'Arrange all the windows so you can see the progress.
WindowArrangeAll
'Activate the source document.
Activate srcDoc$
'Go to the start of the document
StartOfDocument
'Make sure footnote pane is open.
If Not ViewFootnotes() Then ViewFootnotes()
'Make sure cursor is in Footnote pane and at the beginning.
If WindowPane() <> 3 Then OtherPane
StartOfDocument
'Find the first # sign with the Footnote Reference style; this may need 'to be changed to
search for the Endnote Reference style depending on 'which you use. Use a quote to disable
the one you don't use.
'Make sure find formatting options are cleared first.
EditFindClearFormatting
EditFindStyle .Style = "Footnote Reference"
'EditFindStyle .Style = "Endnote Reference"
EditFind .Find = "#"
'Cycle through a loop that collects the context string and pastes it 'into the
"contexts.doc" and continues on until there are no more 'context string
footnotes.
While EditFindFound()
'Ddeselect footnote and skip initial space
CharRight 2
'Select the rest of the paragraph; note: don't use EndOfLine for
'Things like this because you may lose some of the info you want.
'If the line wraps.
ParaDown 1, 1
'Copy the context string and deselect it.
EditCopy
CharRight 1
'Activate "contexts.doc" and insert the context string.
Activate ctxDoc$
EditPaste
'Activate srcDoc in the footnote pane and find the next context.
'String to start the loop over again.
Activate srcDoc$, 3
EditFind
Wend
End Sub
| The Freelance Story Teller |
| Voice: 405 720 7995 |
| Fax: 405 720 7995 |
| 11808 Silvermoon Drive, Oklahoma City, OK 73162 |