Deploying a VBA-macro - vba

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

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.

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).

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:
save the vba in a macro enabled document i.e. a .docm file
in Windows rename the file to be a .doc file
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
ask the user to download the .doc file
ask the user to open the .doc file and ensure that macros are enabled
let the user trial the software in the document
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)
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:
a single document can be used on all versions of Office for Windows from Office 97 to Office 2016 (32 bit and 64 bit).
the install and uninstall all happen within Office so the suer does not need to admin rights over their computer
users do not need to install the software until they have used it in the document
users do not need to use another program to unzip or install the software
Peter Evans

Related

Export visual basic outlook project and add it to other outlook account

I created two macros in Outlook's VB and I want to pass them on to others where I work. Is it possible to do this without copying the code to each account individually? Is there a way to export my project (or my modules) and import it into another account so that the macros I wrote will be added automatically?
Another option for me is whether it can be done in a small program written in C# (i.e. Console Application) with the Outlook namespace.
If you're developing a solution that you intend to distribute to more than a few people, you should convert your VBA code into an Outlook COM or VSTO add-in or an Office add-in for Outlook. However, developing an add-in typically requires considerably more programming knowledge than creating a short macro. If your VBA project is relatively simple, and there aren't too many people that have to use it, you may want to distribute the code together with instructions to set it up.
The easiest solution is to right click on ThisOutlookSession and choose Export File. You'll need to do for each module (if any) in your Project.
Unlike other Microsoft Office programs, Outlook supports only one VBA project at a time. VBA macros are stored in a file that's named VbaProject.OTM. This file is a product storage file and isn't meant for distribution. Outlook doesn't provide a direct means to manage OTM files. Outlook VBA code wasn't designed to be deployed or distributed. It was designed solely to be a personal macro development environment. The project, Project1, is available and associated with the program at all times. It's not possible to add another project in the Visual Basic Editor.
Project1 is stored on your hard disk as VbaProject.otm in the following folder:
<Drive>:\Users\<LogonName>\AppData\Roaming\Microsoft\Outlook
If you want to begin a new VBA project, you could theoretically export all your existing modules and forms. But this is typically not a realistic approach. Instead, follow these steps:
Exit Outlook.
Locate your VbaProject.otm file in the indicated path.
Rename the file to something meaningful to you, such as VbaProject-testing.otm.
Restart Outlook.
Because Outlook can't find an existing project file, Visual Basic Editor starts with a new project. When you save changes to your project, Outlook creates a new VbaProject.otm file in the folder. If you want to switch between projects, add one more step to the previous procedure (as step 4):
Exit Outlook.
Locate your VbaProject.otm file.
Rename the file to something meaningful to you, such as VbaProject-testing.otm.
Restore the name the file that you now want to use as VbaProject.otm.
Restart Outlook.
If you want to move a VBA project from one computer to another, first determine where Outlook is storing the VbaProject.otm files on each computer. Then, copy the OTM file from one computer to the other, and make sure to put it into the correct folder. When you restart Outlook, the program will find the VbaProject.otm file and use it.
You may find the How to backup and save your Outlook VBA macros article helpful.

Word macros disappear on transfer

I'm using Word 2019 and have created macros I want to send to other organisations.
However, when I transfer the document (.docm) or the template (.dotm) the recipient doesn't get the macros (although everything else goes across). On the Developer ribbon, there is no entry for the macro itself or the VBA code.
I know I can export the macro to a *.bas file which the recipient can then import but I'd like to do it directly.
There is no problem with transferring Excel macros but I can't get Word to work.
Can anybody help?
This is most likely to have 2 possible reasons:
Did you really choose "Word Macro-Enabled Document" as file format? It could be that you saved a normal "Word Document" with the file extension .docm. Note that the file extension does not defined the file format.
If this happend you have actually a Word document (without macros) but with the wrong file extension .docm. Make sure you choose the correct format not only the correct extension.
You can easily test this:
Save your file as macro enabled file docm.
Close Word completely.
Re-Open your file. If the macro is still there your file format is correct.
If you send your file via email it can be that your recepient does not allow to recieve macro enabled files, and his email server is stripping off the macro from the Word file.
If this is the case, then you cannot do much to prevent this. It is in the responsibility of the recepient. The only way to get through this kind of filter is to pack your file into a password protected zip archive so the email server cannot access the Word file. But not that doing so can violate the recepients policies. Also if the reciepient's company did it right they won't allow password protected zip archives via email because the could tunnel through their email filters.
Best solution in this case it to provide the file via some cloud share (Google Drive, Dropbox, One Drive, what ever, …) and send the recipient a link only.
That is because of your AV blocking macros to be saved in your PC. Macros have been used in the past by threat actors and Microsoft has applied a protection to them.
When you edit a document with macros, word creates a hidden file which is the macro you are running, now when you try to save that file, it gets caught by AV. Since AV thinks it is an evil activity. It gets saved on your system because your directory is now a Trusted Location and it is okay.
A workaround is to install Windows 7 with Microsoft Office 2007 to get what you want since Windows 7 has little to no security.
Thanks

Can we create and run macros using Outlook addins?

Hi I am just trying to create an addin which can create and run macros. And are there ways to enable the developer ribbon automatically using Addins?
What I am basically looking at is to create a clean way to do all of the above without getting the people who might use the macro going through all the developer's procedures.
After searching for long I just found one article regarding distribution of macros, which didn't mention any specific programmatic way of automating all this.
Article on distributing macros!
Any help would be greatly appreciated.
Thanks guys..
As far as I could find, the scripts cannot be easily created and pushed into Outlook using addins (which is more or less like hosting a web app and opening inside Outlook).
The solution that I came up to my problem was
1) To use a batch file to create the script as .txt file as per the requirement of the user and then renaming the generated .txt file as .bas file at the end of the batch file itself, then importing the bas file from Outlook's VBA editor.
3) The Outlook VBA editor can be opened easily using the shortcut alt + F11.
4) The bas file can be then imported from File options.
5) Create a new Rule with the condition to run the script.

How to password-protect a VbaProjectPart using OpenXml SDK

I have a scenario where users download their Word document from our local server and when they save that document, instead of saving it locally, the document is sent back to the server using a macro (which is "injected" by the server every time a user downloads a document that doesn't contains the latest version of the macro).
Now that we are going to send this solution to our final tests prior deploying it, we needed to protect that macro, I know I can password protect a macro using Microsoft Office by simply right clicking in the macro project inside the document and selecting "block from viewing" and inserting a password.
However, since the macro must be handled by the server, I need to find a way to protect that macro when I generate it, currently the macro is generated using OpenXml SDK using a VbaProjectPart. I couldn't find anything on the web.
Instead of trying to sign and protect the macro programmatically using Open Xml SDK I decided to download the document, sign it and protect it using word then I used "Open Xml SDK Productivity Tools" to "reverse engineer" the DOCM created and then I copied the binary "VbaProjectPart" created by the tool.
It's not the best way to do it since I need to have a separate documentation for this process and need to do the whole process when the macro changes, however, since the code isn't expected to change anymore I decided to go that way.
Hope this helps anyone who wants to know how to include password protected macros inside an Open Xml document.

property promotion in infopath and sharepoint 2010

I have a SharePoint 2010 document library with >7000 xml documents created from infopath forms(Infopath 2007). Now i would like to promote few fields in the form to the SharePoint document library. I could do this only for documents created from the upgraded form, but not for all previously created documents. Although re submitting of old forms will work,It is not possible for me to update all 7000 records to promote the values to the column. Is there a much easier solution, considering the fact that this changes need to be implemented on a production environment too.
Note:The promoted columns will be used to generate graphical report. Any solution acceptable.
I've been through this before, and there's no good answer. If I understand correctly, you have existing InfoPath forms in a doc library, and you now want to promote fields to the document library, but you don't want to open each form one by one, correct?
Note, you most likely don't have to open then re-submit each form, you just have to open the form, and close it. Once you do that, the promoted fields will them show up.
So... what I've done before is this: First, get notepad++ (this allows you to open multiple files in tabs). Secondly, access the the doc library via WebDav (that is, go to the library in SharePoint, then go to the Library tab, and click Open with Explorer). Thirdly, open a large batch of files at once using notepad++ (select files, right-click, open with notepad++). It will take a moment for all the files to load in notepad++ in tabs. Once they are all open in notepad++, hit ctrl-w as fast as you can (which closes each file). Rinse and repeat.
It's not pretty, and I'm sure there's a better way to do this (programatically, perhaps), but this should work. At least you won't have to open each form one by one.
You can do this by relinking the document by powershell or through advanced settings.