我如何将此代码实现到我的Excel加载项? [英] How would I implement this code into my Excel Add-In?

查看:234
本文介绍了我如何将此代码实现到我的Excel加载项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的Excel宏,我变成一个加载项( .xlam )文件,因为我将保持这个加载项的公开版本一个共享网络驱动器我遵循Ken Puls的建议,从这里,通过使用以下代码能够部署我的加载项的未来版本(更新,修复等)。

I have a large Excel macro that I turned into an Add-In (.xlam) file and since I will be keeping the public version of this Add-In on a shared network drive I was following the advice of Ken Puls from here, by using the following code to be able to deploy future versions of my Add-In (for updates, fixes, etc).:

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 Module,Module1(其中包含我的宏)或其他地方?我很困惑,因为安装了加载项的用户不能访问/运行这个 Sub ?我的加载项本身被锁定,不知道是否有帮助,我有一个按钮,放在加载项工具栏区域,用户可以点击运行我的宏。

Now, I understand what's going on in the code, I'm just not sure where this Sub should be placed. Should it be placed in the .xlam's ThisWorkbook Module, Module1 (which houses my macro), or somewhere else? I'm confused because wouldn't the users that have the Add-In installed be able to access/run this Sub? I have the Add-In itself locked, not sure if that helps at all, and I have a button that gets placed on the Add-Ins toolbar area that the users can click to run my macro.

推荐答案

在与网站所有者交谈后,现在明白如何实现上述代码。此子被放置在加载项内的模块中。如果您不希望最终用户具有运行此Sub的访问/能力,则将其设置为私人 Sub(这将清除我的第一个问题)。要运行Sub,您必须在vbe内部,并在Sub中单击光标,然后单击Run按钮。

After talking with the site owner it is now clear on how to implement the above code. This Sub is placed in a Module inside the Add-In. If you don't want end users to have access/ability to run this Sub, then set it as a Private Sub (this clears up my first question). To run the Sub you have to be inside the vbe and have the cursor clicked inside the Sub, then click the Run button.

这篇关于我如何将此代码实现到我的Excel加载项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆