OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Opening a compiled help file

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
FWS
Newbie
Newbie


Joined: 08 Sep 2005
Posts: 2

PostPosted: Mon Aug 30, 2010 2:12 am    Post subject: Opening a compiled help file Reply with quote

Can anyone help me to open a compiled help file from a Calc Macro? I am converting a VBA macro as shown below. When I click the Help button to open the compiled help file (.chm file) OpenOffice crashes with an "unexpected error". If I single step through the code the help file opens correctly and displays the table of contents. If I immediately use the help window to look at a different help page it all works fine. If, when single stepping, I don't touch the help window, or if I don't single step at all it crashes OpenOffice.

I suspect the problem lies in the declaration of the library for the HTMLHelp function, but I cannot find any better sugestion as to what to use.

Thanks, fws
__________________________________

Option Explicit

' HTMLHelpAPI.bas
' You can use this simple module to integrate an HTML Help system
' with your Visual Basic/VBA application.
' Copyright © 2008 HelpSmith.com. All rights reserved.
' http://www.helpsmith.com - Making Help Authoring a Pleasure to Do
Public Const HH_DISPLAY_TOPIC = &H0
Public Const HH_DISPLAY_TOC = &H1
Public Const HH_DISPLAY_INDEX = &H2
Public Const HH_HELP_CONTEXT = &HF
Declare Function HTMLHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" _
(ByVal hwndCaller As Long, ByVal pszFile As String, _
ByVal uCommand As Long, ByVal dwData As Long) As Long

Sub DisplayHelp()
Dim stPath As String
Dim stHelpFileName
Dim stFullHelpPath
Dim lngReturn As Long
Dim Answer As Integer

stHelpFileName = "Cash Book Help OO.chm"
' VBA: stPath = ThisWorkbook.Path
GetThisWorkbookPath(stPath)
stFullHelpPath = stPath & "\" & stHelpFileName
lngReturn = HTMLHelp(0, stFullHelpPath, HH_DISPLAY_TOC, 0)
If lngReturn = 0 Then _
Answer = MsgBox("Can't find the Help file." & _
vbCr & vbCr & "The file: Cash Book Help OO.chm" & _
vbCr & " should be in the same folder as this spreadsheet.", _
vbOKOnly, "Oops")
End Sub

Sub GetThisWorkbookPath(sPath as String)
' Get the path of the current workbook
Dim sURL as String
Dim sChar as String
Dim N as Integer
Dim J as Integer
Dim K as Integer
Dim Nskip as Integer

sURL= ThisComponent.getURL()
' The URL from OpenOffice in the form "file:///C:/Users/My%20Name/Documents/..."
' Whereas VBA uses the form "C:\Users\My Name\..."
N=Len(sURL) ' The no of chars in sURL
' Look for the last "/", so as to remove the file name and give the path.
For J=N to 1 Step -1
sChar = Mid(sURL,J,1)
If sChar = "/" Then
Exit For
EndIf
Next J
N=J-1 ' The length up to but not including the last "/", omitting the file name.
K=1 ' J counts through sURL, K counts through sPath.
Nskip = 0 ' Nskip is used to convert "%20" to " ".
For J=9 to N
sChar = Mid(sURL,J,1)
If Nskip = 2 Then
Nskip = 1 ' omit this character, and the next
Elseif Nskip = 1 Then
Nskip = 0 ' omit this character but not the next.
Elseif sChar = "%" Then
sPath = sPath & " " ' Insert a space character.
Nskip =2 ' Omit this "%", and the next 2 characters.
ElseIf sChar = "/" Then
sPath = sPath & "\" ' Convert "/" to "\".
Else
sPath = sPath & sChar ' Copy this character.
Endif
Next J
End Sub
Back to top
View user's profile Send private message
FWS
Newbie
Newbie


Joined: 08 Sep 2005
Posts: 2

PostPosted: Thu Sep 09, 2010 5:56 am    Post subject: Opening a compiled help file Reply with quote

I've now seen an answer in the Calc forum about batch files that seems to work with help files as well. It's using OpenOffice version 3.2.1 and Windows 7, and it doesn't crash OpenOffice like the example above with the call to HTMLHelp. I hope it's some use to others.

Sub DisplayHelp()
' Display a compiled help file (.CHM file) for this spreadsheet.
' The .CHM file was created using Microsoft HTMLHelp Workshop.
' It's a self-contained program so use SystemShellExecute to display it.
Dim oSvc as Object
Dim strPath As String

' Load the library that includes DirectoryNameoutofPath.
GlobalScope.BasicLibraries.LoadLibrary("Tools")

oSvc = createUnoService("com.sun.star.system.SystemShellExecute")

' Get the URL of the current spreadsheet separated with forward slashes.
strPath = ThisComponent.getURL()
' Separate the directory name from the name of the current spreadsheet.
strPath = DirectoryNameoutofPath(strPath, "/")
' Append the name of the compiled help file.
strPath = strPath & "/HelpFile.chm"

oSvc.execute(strPath, "", 0)
End Sub
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group