View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default programmatically close help file before Excel closes?

Using Excel XP.
I am having the following problem.

Have a userform that can launch a .chm help file with the following code:

'this API function is for displaying the help file
Private Declare Function HtmlHelpTopic Lib "hhctrl.ocx" _
Alias "HtmlHelpA" _
(ByVal hWnd As Long, _
ByVal lpHelpFile As String, _
ByVal wCommand As Long, _
ByVal dwData As String) As Long


Sub ShowHtmlHelp(ByVal strHelpFile As String, _
Optional ByVal strHelpPage As String)

Const HH_DISPLAY_TOPIC As Long = &H0

On Error Resume Next
HtmlHelpTopic 0&, strHelpFile, HH_DISPLAY_TOPIC, strHelpPage

End Sub


Sub ShowHelp()

Dim AddinFolder As String

AddinFolder = _
Left(ThisWorkbook.FullName, Len(ThisWorkbook.FullName) - 21)

ShowHtmlHelp AddinFolder & "\Test.chm"

End Sub


This works all fine.

The problem is when the help file is loaded, the userform gets closed and
then Excel gets closed.
Excel then crashes.
So I have to make sure that the help file gets closed before Excel closes.
Perhaps I need an API function here, but I can't figure it out.
Thanks for any advice.


RBS