我如何将此代码实施到我的 Excel 加载项中?

How would I implement this code into my Excel Add-In?

我有一个很大的 Excel 宏,我把它变成了一个加载项 (.xlam) 文件,因为我将保留此加载项的 public 版本共享网络驱动器 我听从了来自 here 的 Ken Puls 的建议,通过使用以下代码能够部署我的插件的未来版本(用于更新、修复等):

Sub DeployAddIn()
'Author       : 
'Macro Purpose: To deploy finished/updated add-in to a network
'               location as a read only file
    Dim strAddinDevelopmentPath As String
    Dim strAddinPublicPath As String

    'Set development and public paths
    strAddinDevelopmentPath = ThisWorkbook.Path & Application.PathSeparator
    strAddinPublicPath  = "F:\Addins" & Application.PathSeparator

    'Turn off alert regarding overwriting existing files
    Application.DisplayAlerts = False

    'Save the add-in
    With ThisWorkbook
        'Save to ensure work is okay in case of a crash
        .Save

        'Save read only copy to the network (remove read only property
        'save the file and reapply the read only status)
        On Error Resume Next
        SetAttr strAddinPublicPath & .Name, vbNormal
        On Error Goto 0
        .SaveCopyAs Filename:=strAddinPublicPath  & .Name
        SetAttr strAddinPublicPath & .Name, vbReadOnly
    End With

    'Resume alerts
    Application.DisplayAlerts = True
End Sub

现在,我明白了代码中发生的事情,只是不确定 Sub 应该放在哪里。它应该放在 .xlam 的 ThisWorkbook 模块、模块 1(其中包含我的宏)还是其他地方?我很困惑,因为安装了插件的用户不能 access/run 这个 Sub 吗?我锁定了加载项本身,不确定是否有帮助,我有一个按钮放置在加载项工具栏区域,用户可以单击该按钮以 运行 我的宏。

在与网站所有者交谈后,现在清楚了如何实施上述代码。此 Sub 放置在加载项内的模块中。如果您不希望最终用户拥有 access/ability 到 运行 这个 Sub,则将其设置为 Private Sub(这解决了我的第一个问题)。要 运行 Sub,您必须在 vbe 内并在 Sub 内单击光标,然后单击 运行 按钮。