6

I created a VBA-macro which will be used by some word-documents within my company. The macro detects tags and removes chapters from a document. This document is created by another program. So the macro should be separately distributable.

Is it possible to generate an executable which adds the macro to the user running the executable?

Is there another way to package macros and install them on a user's computer?

Thanks

1
  • 2
    Create and distribute an Add-In (dotm for Word, xlam for Excel). You can also create an exe that adds the macro to the file, but it would be much easier to distribute the add-in and just ask them to turn it on,
    – Matteo NNZ
    Commented Apr 21, 2015 at 12:34

3 Answers 3

4

The easiest way to deploy Macros is via a template. Create your Macro and save the file as .dotm (macro-enabled template). I think you will get a suggestion where to save your .dotm-file.

Any colleague who wants to use your template simply has to put it in that directory (I think it's C:\Users\[UserName]\AppData\Roaming\Microsoft\Templates). After that, he should be able to use the macros while working on any word document.

4
  • thought about this but I was hoping that there's an easier way (since I don't want the users having to copy&paste stuff around)
    – keevw
    Commented Apr 21, 2015 at 13:17
  • The user doesn't have to copy paste the file, he can reference it directly in the originary location (a shared folder, the downloads etc.) Of course there's no limit to automation, you might prepare a VBScript to move the file somewhere else, but I dont think it's worthy: this is how we usually distribute VBA code.
    – Matteo NNZ
    Commented Apr 21, 2015 at 13:26
  • The network path is a good approach, but you have to set some registry values for that (altering the trusted locations in word). You can accomplish this via commandline file (.cmd), so colleagues would just execute that file and then they're set.
    – EngJon
    Commented Apr 21, 2015 at 14:26
  • With a .cmd-file on the other hand, you could just automate the process to copy the .dotm-file to the template-location. No touching of the registry required that way.
    – EngJon
    Commented Apr 21, 2015 at 14:29
3

There are basically five ways to do this:

1) Send everyone a text file with your macro that they can paste into their own Normal template. This is fine for very simple macros that are unlikely to have any name conflicts with macros users create themselves, but it does require basic knowledge of the VB editor.

2) Send everyone a .bas file that you create by exporting a module that contains your macro(s). This gives you a little more control and avoids copy/paste errors. Still requires basic understanding of the VB editor (or decent instructions from you).

3) Package your macros in a template (.dotm file) that lives in the Templates folder. Users can apply that template to any document they're creating and gain access to your macro(s). No VB knowledge required; this is done through the standard Word New File process. Also allows you to include styles or other things if you want.

4) Package your macros as a global template (.dotm file) that lives in the Startup folder. Users will have access to your macro(s) in every file they work on, no need to apply your template. This is good if what you are doing is central to your team's workflow and doesn't require that you include styles with your macro. You can also build in UI elements. (There can be issues with this approach in Word 2011; users may not have immediate access to the global template but it is easy enough to get back.)

Both 3 and 4 do require that the user initially place the .dotm file in the right place. You can help them with this (one approach is to use another Word doc as a "setup" file that, when run, places the template in the presumed correct folder). Obviously that requires more work on your part so how far you'd want to go with that depends on you and your business needs.

5) Additionally, if you have control over the creation of the document itself (rather than just the macro) you can embed a macro in the document. You can place the macro itself in the document's ThisDocument module (find your document in the Project Explorer and then open Microsoft Word Objects). Then save the document as .docm (macro-enabled document). Users should be instructed to enable macros when they open the document (different versions of Word use slightly different interfaces for prompting the user about this, but it's always pretty obvious).

2
  • users are not creating a new document, they receive one (not from me) and will have to use my macro on the received document... so my only is number 4? or is there a way to include a macro in a certain document? (so I could give my macro to the producer of the document and tell them to include it?)
    – keevw
    Commented Apr 27, 2015 at 8:12
  • Ah, if you actually have control over the creation of the document you can embed a macro in it. I'll update my answer to include that scenario.
    – Christina
    Commented Apr 27, 2015 at 14:17
1

Over the last 7 years I have been deploying my Word VBA in a different way. The software is a Word add-in that makes it easier for teachers to provide feedback on assignments. It is distributed as a 30 day trial and if the user buys it they are given a key which enables them to use eMarking Assistant for a year. You can test the deployment system at http://eMarkingAssistant.com

The deployment and licensing mechanism is given below:

  1. save the vba in a macro enabled document i.e. a .docm file
  2. in Windows rename the file to be a .doc file
  3. use Orlando's excellent "VBA decompiler and compacter" from http://orlando.mvps.org/VBADecompilerMore.asp to remove compiled code and references to specific Office versions from the .doc and compact the document
  4. ask the user to download the .doc file
  5. ask the user to open the .doc file and ensure that macros are enabled
  6. let the user trial the software in the document
  7. if they want to use the software in any document they click an "install" button in the document to copy the vba code to to a .dotm file in their Word startup folder (so it is loaded automagically)
  8. if they want to buy a subscription to use the software, they pay using paypal and I send them a key which unlocks the software until the end of the subscription

Advantages of this process are:

  1. a single document can be used on all versions of Office for Windows from Office 97 to Office 2016 (32 bit and 64 bit).
  2. the install and uninstall all happen within Office so the suer does not need to admin rights over their computer
  3. users do not need to install the software until they have used it in the document
  4. users do not need to use another program to unzip or install the software

Peter Evans

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.