ID: Q126087
The information in this article applies to:
This article describes how to use WordBasic to load your own Windows Help file.
Below is a sample WordBasic macro that calls the WinHelp() Windows API function.
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
REM The declaration for WinHelp is as follows:
Declare Sub WinHelp Lib "User" (hWnd As Integer, lpHelpFile$ As String,
REM The GetFocus SDK function to obtain the handle of Word which is the REM hWnd parameter to WinHelp
Declare Function GetFocus Lib "User"() As Integer
Sub Main
 hWnd = GetFocus
 WinHelp (hWnd, "c:\winword\winword.hlp", 3, 0)
End Sub
REM The declaration for WinHelp32 is as follows:
Declare Function WinHelp Lib "user32" Alias "WinHelpA"(hwnd As Long,
REM The GetFocus SDK function to obtain the handle of Word which is the REM hWnd parameter to WinHelp
Declare Function GetFocus Lib "user32" Alias "GetFocus"() As Long
Sub Main
End Sub
The hWnd parameter is the window handle to Word, the active application.
The lpHelpFile$ parameter is the path and name of the Help file.
The wCommand parameter to the WinHelp function is set to the number 3 so that Help will display the contents or first page of the Help file.
See below for an explanation of the dwData parameter.
You can also go to a particular section of a Help file depending upon a keyword by doing the following:
1. In your Help file, create a footnote that contains a keyword.
2. From the Insert menu, choose Footnote.
3. Select Custom Mark and type the letter "K" (without the quotation
   marks).
For example, if you define a Keyword called "normal view" in your Help file, call it this way:
Declare Sub WinHelp Lib "User" (hWnd As Integer, helpfilename$ As String,
Declare Function GetFocus Lib "User"() As Integer
Sub Main
 helpfilename$ = "c:\winword\winword.hlp"
 hwnd = GetFocus
 text$ = "normal view"
 WinHelp(hwnd, helpfilename$, 257, text$)
End Sub
Declare Function WinHelp Lib "user32" Alias "WinHelpA"(hwnd As Long,
Declare Function GetFocus Lib "user32" Alias "GetFocus"() As Long
Sub Main
 helpfilename$ ="c:\msoffice\winword\wrdbasic.hlp"
 hWnd = GetFocus
 text$ = "msgbox$"
 WinHelp(hWnd, helpfilename$, 257, text$)
End Sub
NOTE: Always call dwData as String from 32 bit versions of Word.
wCommand parameter     Defined in Windows.H     Decimal Equivalent
==================     ====================     ==================
HELP_CONTEXT           0x0001                   1
HELP_QUIT              0x0002                   2
HELP_INDEX             0x0003                   3
HELP_CONTENTS          0x0003                   3
HELP_HELPONHELP        0x0004                   4
HELP_SETINDEX          0x0005                   5
HELP_SETCONTENTS       0x0005                   5
HELP_CONTEXTPOPUP      0x0008                   8
HELP_FORCEFILE         0x0009                   9
HELP_KEY               0x0101                   257
HELP_COMMAND           0x0102                   258
HELP_PARTIALKEY        0x0105                   261
Microsoft Word for Windows 6.0 On-Line Help, WordBasic, Declare Example
Microsoft Windows SDK "Programming Tools," Chapter 3, "Creating Help Files"
Microsoft Windows SDK "Programmer's Reference, Volume 2: Functions," pages 985-988
KBCategory: kbmacro KBSubcategory: Additional query words: 2.0 2.0a 2.0a-CD 2.0b 2.0c 6.0 6.0a winword 7.0 word95 word7 word6 6.0c winword winword2 winapi
Keywords          : kbinterop kbmacro
Version           : 2.x 6.0 6.0a 6.0c 7.0
Platform          : WINDOWS
Issue type        : kbhowtoLast Reviewed: February 5, 1998