Excel 2010“此功能的帮助”不会使用-mapid参数启动HH.EXE

时间:2014-12-18 22:26:51

标签: excel chm

我正在使用CHM帮助文件开发Excel加载项。 CHM有我想要从Excel的“插入函数”对话框中访问的主题。当我按如下方式调用HH.EXE时确认:

HH.EXE -mapid 1234“mk:@MSITSTORE:< path-to-my-chm-file>”

我使用Application.MacroOptions()函数注册了所有UDF,并传递了相应的参数(Macro,Category,HelpContextID和HelpFile)。

当我单击“此功能上的帮助”链接时,将使用我的CHM的正确路径和文件名调用HH.EXE。但是,没有-mapid参数用于调用HH.EXE。因此,当我的CHM文件被加载时,HH没有转到所需的主题。

有没有人知道或猜测为什么Excel可能会省略此参数?

谢谢!

1 个答案:

答案 0 :(得分:1)

据我了解,你想要快照中显示的内容。上下文相关的帮助很复杂。

我为调用HTMLHelp(CHM)API的按钮和代码添加了示例代码。

Office 2007仅安装在我的计算机上。

enter image description here

这是通过HTMLHelp API调用(代码段(1))完成的:

    '******************************************************************************
    '----- Modul - definition for HTMLHelp
    '----- (c) Ulrich Kulle, http://www.help-info.de/en/Visual_Basic_Applications/vba.htm
    '----- 2002-08-26 Version 0.2.xxx
    '******************************************************************************
    '----- Portions of this code courtesy of David Liske.

    Declare Function IsWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

    Private Declare Function SendMessage Lib "user32" _
     Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
     ByVal wParam As Long, lParam As Any) As Long

    Private 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

    Declare Function HTMLHelpTopic Lib "hhctrl.ocx" Alias "HtmlHelpA" _
             (ByVal hwndCaller As Long, ByVal pszFile As String, _
             ByVal uCommand As Long, ByVal dwData As String) As Long

    Private Declare Function HtmlHelpSearch Lib "hhctrl.ocx" Alias "HtmlHelpA" _
            (ByVal hwndCaller As Long, ByVal pszFile As String, _
            ByVal uCommand As Long, dwData As HH_FTS_QUERY) As Long

    '--- to keep the handle of the HH windows when calling help by API --------
    Public HHwinHwnd As Long

    '--- some constants used by the API ---------------------------------------
    Public Const HH_DISPLAY_TOPIC = &H0     ' select last opened tab, [display a specified topic]
    Public Const HH_DISPLAY_TOC = &H1       ' select contents tab, [display a specified topic]
    Public Const HH_DISPLAY_INDEX = &H2     ' select index tab and searches for a keyword
    Public Const HH_DISPLAY_SEARCH = &H3    ' select search tab and perform a search

    Public Const HH_HELP_CONTEXT = &HF      ' display mapped numeric value in dwData

    Public Const HH_CLOSE_ALL = &H12


    Public Type HH_FTS_QUERY                ' UDT for accessing the Search tab
      cbStruct          As Long             ' Sizeof structure in bytes.
      fUniCodeStrings   As Long             ' TRUE if all strings are unicode.
      pszSearchQuery    As String           ' String containing the search query.
      iProximity        As Long             ' Word proximity.
      fStemmedSearch    As Long             ' TRUE for StemmedSearch only.
      fTitleOnly        As Long             ' TRUE for Title search only.
      fExecute          As Long             ' TRUE to initiate the search.
      pszWindow         As String           ' Window to display in
    End Type

    Public Function HFile(ByVal i_HFile As Integer) As String
    '----- Set the string variable to include the application path of helpfile
      Select Case i_HFile
      Case 1
        HFile = ThisWorkbook.Path & "\CHM-example.chm"
      Case 2
    '----- Place other Help file paths in successive case statements
        HFile = ThisWorkbook.Path & "\CHM-example.chm"
      End Select
    End Function

    Public Sub ShowContents(ByVal intHelpFile As Integer)
       HHwinHwnd = HtmlHelp(hwnd, HFile(intHelpFile), HH_DISPLAY_TOC, 0)
    End Sub

    Public Sub ShowIndex(ByVal intHelpFile As Integer)
        HHwinHwnd = HtmlHelp(hwnd, HFile(intHelpFile), HH_DISPLAY_INDEX, 0)
    End Sub

    Public Sub ShowTopic(ByVal intHelpFile As Integer, strTopic As String)
        HHwinHwnd = HTMLHelpTopic(hwnd, HFile(intHelpFile), HH_DISPLAY_TOPIC, strTopic)
    End Sub

    Public Sub ShowTopicID(ByVal intHelpFile As Integer, IdTopic As Long)
      HHwinHwnd = HtmlHelp(hwnd, HFile(intHelpFile), HH_HELP_CONTEXT, IdTopic)
    End Sub

    Public Sub CloseHelp(ByVal hwnd As Long)
    Const WM_CLOSE = &H10
    If IsWindow(hwnd) Then
      SendMessage hwnd, WM_CLOSE, 0, 0
    End If
    End Sub
    '------------------------------------------------------------------------------
    '----- display the search tab
    '----- bug: start searching with a string dosn't work
    '------------------------------------------------------------------------------
    Public Sub ShowSearch(ByVal intHelpFile As Integer)
    Dim searchIt As HH_FTS_QUERY
      With searchIt
        .cbStruct = Len(searchIt)
        .fUniCodeStrings = 1&
        .pszSearchQuery = "foobar"
        .iProximity = 0&
        .fStemmedSearch = 0&
        .fTitleOnly = 1&
        .fExecute = 1&
        .pszWindow = ""
      End With
      Call HtmlHelpSearch(0&, HFile(intHelpFile), HH_DISPLAY_SEARCH, searchIt)
    End Sub

并添加了一些示例代码(2):

    Sub AddUDFToCategory()
    '------------------------------------------------------------------------------
    ' insert after Description line [optional]:    Category:=2, _ => Date & Time
    '------------------------------------------------------------------------------
    ' If the UDF's are in an Addin (.xla) it's better to qualify the function name
    ' like this:
    ' Macro:=ThisWorkbook.Name & "!" & "DayName"
    '------------------------------------------------------------------------------
    ' see also Excel help for Application.MacroOptions
    '------------------------------------------------------------------------------
        application.MacroOptions _
            Macro:="TestMacro", _
            Description:="This function gives back the 'Hello world' message!", _
            Category:=2, _
            HelpFile:=ThisWorkbook.Path & "\CHM-example.chm", _
            HelpContextID:=10000
        application.MacroOptions _
            Macro:="DayName", _
            Description:="A Function That Gives the Name of the Day", _
            Category:=2, _
            HelpFile:=ThisWorkbook.Path & "\CHM-example.chm", _
            HelpContextID:=20000
    End Sub

    Function TestMacro()
    '----------------------------------------------------------------
    ' Display a message box with a help button linked to a help topic
    '----------------------------------------------------------------
        MsgBox "The 'Hello World' message for testing this function!.", _
        Buttons:=vbOKOnly + vbMsgBoxHelpButton, _
        HelpFile:=ThisWorkbook.Path & "\CHM-example.chm", _
        Context:=20010
    End Function

    Function DayName(InputDate As Date)
    '---------------------------------------------
    '--- A Function That Gives the Name of the Day
    '--- http://www.fontstuff.com/vba/vbatut01.htm
    '---------------------------------------------
        Dim DayNumber As Integer
        DayNumber = Weekday(InputDate, vbSunday)
        Select Case DayNumber
            Case 1
                DayName = "Sunday"
            Case 2
                DayName = "Monday"
            Case 3
                DayName = "Tuesday"
            Case 4
                DayName = "Wednesday"
            Case 5
                DayName = "Thursday"
            Case 6
                DayName = "Friday"
            Case 7
                DayName = "Saturday"
        End Select
    End Function

有关工作示例,请转到Online Help and Visual Basic for Applications 请。搜索VBA - 下载和下载链接Download Visual Basic for Applications example project (EXCEL)

  1. 将ZIP文件从上面的链接下载到临时目录,首先右键单击保存的ZIP文件,单击属性,然后单击取消阻止
  2. 解压缩到临时目录。
  3. 首先双击作为测试打开CHM文件
  4. 双击CHM_VBA_example.xls
  5. 首先查看安全警告(Excel)并设置为“激活”
  6. 按照Excel示例工作表中的说明进行操作。
  7. 有关详细信息,请阅读Using the VBA Excel Example File