also where does the file have to reside?
Printable View
also where does the file have to reside?
In the same directory as the workbook that builds the buttons. You can move it, b ut adjust the code to suit.
Ok still confused. Im uploading my WB for you to look at. I added the .chm file into the VBA project properties in the VBE editor. Not sure how to proceed from there. Could you tidy it up for me?
Also is the file attached to the WB if I do that. So if I send this to someone else they will see the help files? Thanks
You need to save the help file in the same directory as the workbook.
Add that code I gave you.
Link the help button to that code.
So the user has to have the help file and the workbook. Say both of them on their desktop?
Yes, both wherever they will be stored.
ok got it thank again.
Hmmm... the code you gave me for the button Bob, won't compile. I get a "only comments are allowed after End Sub, End Function or End Property" on the lines in red.
[VBA]Option Explicit
Sub Button138_Click()
Option Private Module
Private Const mmModuule As String = "mhHTMLHelp"
Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" ( _
ByVal hWnd As Long, _
ByVal lpHelpFile As String, _
ByVal wCommand As Long, _
ByVal dwData As Long) As Long
Const HH_DISPLAY_TOPIC = &H0
Const HH_SET_WIN_TYPE = &H4
Const HH_GET_WIN_TYPE = &H5
Const HH_GET_WIN_HANDLE = &H6
Const HH_DISPLAY_TEXT_POPUP = &HE ' Display string resource ID or text in a pop-up window.
Const HH_HELP_CONTEXT = &HF ' Display mapped numeric value in dwData.
Const HH_TP_HELP_CONTEXTMENU = &H10 ' Text pop-up help, similar to WinHelp's HELP_CONTEXTMENU.
Const HH_TP_HELP_WM_HELP = &H11 ' text pop-up help, similar to WinHelp's HELP_WM_HELP.
'---------------------------------------------------------------------------
Public Sub ColgateOpenHelp(ByVal ContextId As Long)
'---------------------------------------------------------------------------
' Function: Opens the HTML help file
'---------------------------------------------------------------------------
Dim hwndHelp As Long
'The return value is the window handle of the created help window.
Dim hwndHH
hwndHH = HtmlHelp(0, ThisWorkbook.Path & "\Colgate.chm", HH_HELP_CONTEXT, ContextId)
End Sub
'---------------------------------------------------------------------------
Public Sub StartHelp()
'---------------------------------------------------------------------------
ColgateOpenHelp 1000
End Sub
[/VBA]
[vba]
Option Explicit
Option Private Module
Private Const mmModuule As String = "mhHTMLHelp"
Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" ( _
ByVal hWnd As Long, _
ByVal lpHelpFile As String, _
ByVal wCommand As Long, _
ByVal dwData As Long) As Long
Const HH_DISPLAY_TOPIC = &H0
Const HH_SET_WIN_TYPE = &H4
Const HH_GET_WIN_TYPE = &H5
Const HH_GET_WIN_HANDLE = &H6
Const HH_DISPLAY_TEXT_POPUP = &HE ' Display string resource ID or text in a pop-up window.
Const HH_HELP_CONTEXT = &HF ' Display mapped numeric value in dwData.
Const HH_TP_HELP_CONTEXTMENU = &H10 ' Text pop-up help, similar to WinHelp's HELP_CONTEXTMENU.
Const HH_TP_HELP_WM_HELP = &H11 ' text pop-up help, similar to WinHelp's HELP_WM_HELP.
'---------------------------------------------------------------------------
Public Sub ColgateOpenHelp(ByVal ContextId As Long)
'---------------------------------------------------------------------------
' Function: Opens the HTML help file
'---------------------------------------------------------------------------
Dim hwndHelp As Long
'The return value is the window handle of the created help window.
Dim hwndHH
hwndHH = HtmlHelp(0, ThisWorkbook.Path & "\Colgate.chm", HH_HELP_CONTEXT, ContextId)
End Sub
'---------------------------------------------------------------------------
Public Sub Button138_Click()
'---------------------------------------------------------------------------
ColgateOpenHelp 1000
End Sub
[/vba]
Edit: Woops, sorry xld, I didn't see that you had posted.
Edit#2 Please correct me if I'm wrong with what I described below, as it did work that way when I tested it.
Edit#3 xld.. After looking again I do see that the StartHelp Sub that I used below is not needed, in favor of the code you gave.
I believe you need to put this part of the code in it's own module.
[vba] Option Private Module
Option Explicit
Private Const mmModuule As String = "mhHTMLHelp"
Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" ( _
ByVal hWnd As Long, _
ByVal lpHelpFile As String, _
ByVal wCommand As Long, _
ByVal dwData As Long) As Long
Const HH_DISPLAY_TOPIC = &H0
Const HH_SET_WIN_TYPE = &H4
Const HH_GET_WIN_TYPE = &H5
Const HH_GET_WIN_HANDLE = &H6
Const HH_DISPLAY_TEXT_POPUP = &HE ' Display string resource ID or text in a pop-up window.
Const HH_HELP_CONTEXT = &HF ' Display mapped numeric value in dwData.
Const HH_TP_HELP_CONTEXTMENU = &H10 ' Text pop-up help, similar to WinHelp's HELP_CONTEXTMENU.
Const HH_TP_HELP_WM_HELP = &H11 ' text pop-up help, similar to WinHelp's HELP_WM_HELP.
'---------------------------------------------------------------------------
Public Sub ColgateOpenHelp(ByVal ContextId As Long)
'---------------------------------------------------------------------------
' Function: Opens the HTML help file
'---------------------------------------------------------------------------
Dim hwndHelp As Long
'The return value is the window handle of the created help window.
Dim hwndHH
hwndHH = HtmlHelp(0, ThisWorkbook.Path & "\Colgate.chm", HH_HELP_CONTEXT, ContextId)
End Sub
'---------------------------------------------------------------------------
Public Sub StartHelp()
'---------------------------------------------------------------------------
ColgateOpenHelp 1000
End Sub[/vba] And only this for your Button
[vba]Sub Button138_Click()
StartHelp
End Sub[/vba]
Here is an updated file
Thanks.