3

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!

Community
  • 1
  • 1
tomek198823
  • 115
  • 2
  • 11
  • Why not just host the workbook containing all of this logic and VBA on a shared drive or sharepoint (if you have it). Then you can update the logic and save it back out there and whoever opens it has the latest version. You COULD create an add-in and that add-in could do the things you want... but it sounds like a painful path to take. And you will end up in the same boat... how do you update an add in on someone elses computer? – JNevill May 22 '18 at 17:31
  • 3
    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. – braX May 22 '18 at 17:34
  • @braX - make this an answer so I can upvote it – Sam May 22 '18 at 18:24

2 Answers2

7

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.

braX
  • 11,506
  • 5
  • 20
  • 33
4

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.

Victor K
  • 1,049
  • 2
  • 10
  • 21
  • I have one question about the name of the local copy of the wrokbook and the copy on shared drive. Shouldn't names of them differ from each other? When I try to open local copy I get a message that file with the same name is already open - this file is an addin (it needs to be instaled on my drive). Am I doing something wrong here? – tomek198823 Jun 11 '18 at 17:47
  • @tomek198823 You, of course, can change the name of the add-in either for clarity of if you plan to have both versions open at the same time (f.esk `.Name & " - production"`. I normally never have both open at the same time to avoid confusion – Victor K Jun 11 '18 at 18:31
  • @tomek198823 Do not open the XLAM by double clicking it. Never open the copy on the network drive. It's there only for the others to use. – braX Nov 16 '21 at 21:22