How to open a help document from vba

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

How to open a help document from vba

Post by chamdan »

Hi,

I have a Help document located at this address: "C:\D-Drive\WISDDM\PLANNER\PLANHELP.HLP
How would you call it using vba?

I tried

Code: Select all

Application.Run   "C:\D-Drive\WISDDM\PLANNER\PLANHELP.HLP
" but it did not execute. A small macro showing how would certainly be appreciated.

Chuck

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to open a help document from vba

Post by HansV »

The .hlp file format was used in Windows XP and earlier versions of Windows. Recent versions of Windows have no built-in support for them. Which version of Windows are you using?
Best wishes,
Hans

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: How to open a help document from vba

Post by chamdan »

Window 7 Professional

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: How to open a help document from vba

Post by chamdan »

I tried the following:

Code: Select all

Sub TestHlp()
Dim Hlp As Object

Helping = "C:\D-Drive\WISDDM\PLANNER\PLANHELP.HLP"    ' Define Help file.
 Hlp CreateObject("Help.Application")
    Hlp.Open (Helping)
    Hlp.Visible = True
    
End Sub
But I am getting the following message:
error.jpg
You do not have the required permissions to view the files attached to this post.

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: How to open a help document from vba

Post by Doc.AElstein »

Does this sort of thing do anything for you?

Code: Select all

Sub GetHelp()
Dim Cnt As Long
On Error GoTo Bed
 Let Cnt = 1 / 0
Bed:
 Application.Help HelpFile:=Err.HelpFile, HelpContextID:=Err.HelpContext
 Debug.Print Err.HelpFile & "   " & Err.HelpContext
End Sub
For me it brings up a help window, and this in the Immediate window:
C:\PROGRA~1\COMMON~1\MICROS~1\VBA\VBA6\1031\VbLR6.chm 1000011
Help.JPG
You do not have the required permissions to view the files attached to this post.
Last edited by Doc.AElstein on 23 Jan 2019, 20:23, edited 1 time in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to open a help document from vba

Post by HansV »

Thanks. You'll need to install WinHelp32, the application needed to view .hlp files. You can download it from Error opening Help in Windows-based programs: "Feature not included" or "Help not supported"
Let me know if your code works after that.
Best wishes,
Hans

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: How to open a help document from vba

Post by chamdan »

I tried to install it the windows 7 64 bit version but it displayed a message saying that the update was already installed. Then I tried a gain to run the macro but same message appeared.

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: How to open a help document from vba

Post by chamdan »

Hans,

If I double click the help document from inside the folder it opens.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to open a help document from vba

Post by HansV »

Create a new module in the Visual Basic Editor (Insert | Module)
Copy the following code into the module:

Code: Select all

Public Declare Function ShellExecute _
  Lib "shell32.dll" Alias "ShellExecuteA" ( _
  ByVal hwnd As Long, _
  ByVal lpOperation As String, _
  ByVal lpFile As String, _
  ByVal lpParameters As String, _
  ByVal lpDirectory As String, _
  ByVal nShowCmd As Long) As Long

Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMAXIMIZED = 3
Change the macro to open the help file as follows:

Code: Select all

Sub TestHlp()
    Dim Helping As String
    Helping = "C:\D-Drive\WISDDM\PLANNER\PLANHELP.HLP"    ' Define Help file.
    ShellExecute Application.hWnd, "Open", Helping, 0&, 0&, SW_SHOWNORMAL
End Sub
If you'd like the help file to be opened in a maximized window, change SW_SHOWNORMAL to SW_SHOWMAXIMIZED.
Best wishes,
Hans

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: How to open a help document from vba

Post by chamdan »

Hans you deserve a nice and cold :cheers: :clapping: :thankyou:

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to open a help document from vba

Post by HansV »

Thanks! :thankyou:
Best wishes,
Hans