Distributing macro as an Add-In to other users

寵の児 提交于 2020-02-24 11:17:47

问题


I am looking for some tips how to resolve a problem with distributing macro to other users in my company.

I’ve created a specific workbook which holds a bunch of various types of data such as dates, strings and numbers. Each of the users have to manage the same types of data, so we use this workbook as a template. Data is stored in a columns to which I’ve applied a conditional formatting and data validation to prevent users from inserting wrong values. This Workbook contains few Worksheets with specific names. Names of this worksheets appear in the code – to make some specific calculations for each one of them (based on the name of the worksheet).

The problem is that there is a probability that in the future I would like to make some changes to the code for example to make my macro more efficient or to implement some changes that are necessary.

I’ve searched through the internet to find the best solution and I think the best is to create an Add-In to Excel. But I’ve some questions about that.

  1. Is this really the best solution? Can someone give me a hint to make it in a better way?

  2. If Add-In is the best, is there a way to add this only to specific workbooks (which are my template)?

  3. Is it possible to install Add-in when someone opens a specific workbook (using Workbook_Open) and uninstall it when workbooks is closing (using Workbook_BeforeClose). I’ve looked for answers on the web, but this matter is not clear to me. If this is possible, would it affect speed of the closing/opening workbooks?

Thanks for any help/advice!


回答1:


For distributing an add-in through a shared drive with your own development copy I would highly suggest to read the following link. It has a description of the installation process, including a very important point that braX brought up in his answer - answering No when asked about copying to personal add-in folder.

Below is an adjusted code from the link that I use to save add-ins. It goes into a normal module in the add-in itself. It saves an add-in a folder and sets its attribute to Read only so that whenever it is used by somebody it will not be locked. This setup allows you to update the file by running this macro at any time without needing to chase down users and get them to close Excel.

Private Sub Deploy()
Dim FolderOnSharedDrive as String
FolderOnSharedDrive = "Folder path to store add-in in here"
With ThisWorkbook
    On Error Resume Next
    SetAttr FolderOnSharedDrive  & .Name, vbNormal
    On Error GoTo 0
    .SaveCopyAs FolderOnSharedDrive  & .Name
    SetAttr FolderOnSharedDrive  & .Name, vbReadOnly
    MsgBox "Deploy Completed to " & FolderOnSharedDrive  & .Name
End With
End Sub

It is a good idea to add checks for filepath and perhaps some error-handling. As to some other issues you bring up:

  • Add-ins can include worksheets that are not visible that you can use to store settings, paths, etc.
  • It is possible to make add-in appear only on specific workbooks but it will take some effort:

    1. Include a ribbon for an add-in that includes callback for visibility. Set it to visible whenever specific workbook(template) is active. It will still be loaded to memory in any Excel instance

    2. You can programatically add add-ins on open and remove on close as you suggested, check this question to see some options.

  • Adding/removing add-ins on close or open will definitely affect the speed, but I cannot say if it will be noticeable.




回答2:


Put the add-in on the network drive and mark it as read-only. Use a local copy to make updates. Make sure to set it to read only each time you copy it, and make sure people are running off the network drive.

Often times when people install an Add-In, they answer YES to the question about copying it to their local drive and that is not the right answer. If they accidentally click YES you will need to edit their registry to remove the local reference.



来源:https://stackoverflow.com/questions/50473365/distributing-macro-as-an-add-in-to-other-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!