'方法一 Option Explicit Private 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 Private Const SW_SHOW = 5 '方法二 Private Declare Function HtmlHelpA Lib "hhctrl.ocx" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long Const HH_DISPLAY_TOPIC = &H0 Const HH_DISPLAY_INDEX = &H2 Const HH_HELP_CONTEXT = &HF Const HH_DISPLAY_SEARCH = &H3 Const HH_DISPLAY_TEXT_POPUP = &HE '指定CHM文件的位置 Private Sub Command1_Click() Dim nRet As Integer If Len(App.HelpFile) = 0 Then MsgBox "没有找到CHM文件", vbInformation, Me.Caption Else On Error Resume Next SendKeys "{F1}" If Err Then MsgBox Err.Description End If End If End Sub
Option Explicit
Private 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
Private Const SW_SHOW = 5
'方法二
Private Declare Function HtmlHelpA Lib "hhctrl.ocx" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long
Const HH_DISPLAY_TOPIC = &H0
Const HH_DISPLAY_INDEX = &H2
Const HH_HELP_CONTEXT = &HF
Const HH_DISPLAY_SEARCH = &H3
Const HH_DISPLAY_TEXT_POPUP = &HE
'指定CHM文件的位置
Private Sub Command1_Click()
Dim nRet As Integer
If Len(App.HelpFile) = 0 Then
MsgBox "没有找到CHM文件", vbInformation, Me.Caption
Else
On Error Resume Next
SendKeys "{F1}"
If Err Then
MsgBox Err.Description
End If
End If
End Sub