PDA

View Full Version : Help button to open pdf or chm



hunsnowboard
01-30-2009, 09:35 AM
Hi there Everyone! I have the following problem. I have a userform in a macro. I added a 'Help' button to this userform. I would like the help button to do the following if pressed:
First try to open the 'helpbook.pdf' file with acrobat reader. If there is no acrobat reader in the computer then, open the 'helpbook.chm' file. Both files are in the same workbook in which the excelfile is.

Thank you in advance!

lucas
01-30-2009, 09:54 AM
Both files are in the same workbook in which the excelfile is

Do you mean you have embedded them? I would think that developing msgbox would be easier than this and be a smaller file at the same time....

Or a simple userform with a label....

Kenneth Hobs
01-30-2009, 10:17 AM
I think you mean that they are external files in the same folder as that workbook.

You can use kind of thing to find what you need.
'http://www.pcreview.co.uk/forums/thread-2660940.php
Private Declare Function FindExecutable& Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile$, ByVal lpDirectory$, ByVal lpResult$)

Private Function GetFileAssociation$(ByVal sFile$)
GetFileAssociation = "File not found !"
If Dir(sFile) = "" Or sFile = "" Then Exit Function
GetFileAssociation = "No association found !"
Dim i&, E$: E = String(260, Chr$(0))
i = FindExecutable(sFile, vbNullString, E)
If i > 32 Then GetFileAssociation = Left$(E, InStr(E, Chr$(0)) - 1)
End Function

Private Sub test()
Dim s As String
s = ThisWorkbook.FullName
MsgBox GetFileAssociation(s), , s
End Sub

hunsnowboard
01-30-2009, 03:00 PM
Hi Everyone! Hobs is right. These are two external files. One is pdf and the other is chm. When the help button is pressed I would like excel to open the pdf with adobe acrobat and if there is no acrobat installed on the computer, then open the chm file.

Kenneth Hobs
01-30-2009, 03:34 PM
Did my routine not help?

You can change it a bit to return nothing if it did not find the exe's path. If you pass GetEXE() a valid pdf name with the full path, it will return the path to say adobe reader if associated with pdfs or nothing if none is set. If nothing is returned call your chm. You can use Shell() to launch your external files. For chm, I generally Shell to hh.exe and pass the chm to it in the Shell()
e.g.

Private Declare Function FindExecutable& Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile$, ByVal lpDirectory$, ByVal lpResult$)

Private Function GetEXE(ByVal sFile$) As String
If Dir(sFile) = "" Or sFile = "" Then Exit Function
Dim i&, E$: E = String(260, Chr$(0))
i = FindExecutable(sFile, vbNullString, E)
If i > 32 Then GetEXE = Left$(E, InStr(E, Chr$(0)) - 1)
End Function

Private Sub test()
Dim s As String
s = ThisWorkbook.FullName & "1"
MsgBox GetEXE(s), , s
End Sub