How can I expose Word VBA macro code as text files in VSC to better commit and track code changes? - vba

Background and Problem
I lead a team of tech writers. Our team has a Word template (.dotm file) that has a bunch of VBA macros we've created over the years to help us automate tasks in Word. The macros are obviously stored inside of a .dotm template. Given that the code is stored in a binary file, the code is not easily traceable across commits.
Currently, we have to pull the changes on the branch and then open the macro inside Word's embedded code editor from the .dotm. But there's no way to see what exact code changes someone else made line by line or resolve conflicts using something like Beyond Compare.
What I Need
I'd like to find a way to automatically expose the VBA code from the .dotm as some kind of text file so that we can:
Do Word VBA coding tasks within VSC
Easily track and review each others code changes at the line level using our git repository
Resolve merge conflicts more easily
Has anyone found a way to do this?
What I've tried
I've tried searching online and on stackoverflow.
Hoping it might help, I installed ScriptLab, and I after following the MS tutorial, I now have Office Add-Ons working with VSC.
(https://code.visualstudio.com/docs/other/office),
(https://learn.microsoft.com/en-us/office/dev/add-ins/tutorials/word-tutorial) While the Office Add-Ons through VSC does provide an alternate (more modern) way of automating using Javascript, and the .js files are commit-able, it's not providing a way to expose the Word VBA, at least not that I could see.
Thank you in advance!

ScriptLab add-on is for playing with JavaScript code instantly, not designed as a macro infrastructure in Office.
Sounds like you need to switch your VBA macros to COM add-ins rails. There is no converters that can do this part of work for you automatically.
You may consider creating a VB.NET based add-in. In that case you will avoid language translating issues. You may find the Converting Code from VBA to Visual Basic .NET article helpful. It presents issues to consider when converting your Microsoft Office solutions from Visual Basic for Applications (VBA) to Visual Basic .NET. Provides a general overview of their differences, and then uses examples from Word and Excel to describe how you can use Visual Studio Tools for the Microsoft Office System to convert your code.

Related

How to save a word macro as an add-in

Trying to save a MS Word macro as an add-in, fully independent, portable and installable as a word tool. What kind of literature should I consult to learn this technique?
So far I've tried looking on Google and StackOverflow. Many people ask similar questions, no one seems to provide a valid answer.
In the end, I would like to be able to export a macro in the form of a exe/batch/whatever to be summoned/installed from word and customize the tools ribbon permanently, to conceal the macro sourcecode and easily propagate to other machines.
It's not possible to use VBA macros as exe or batch files. It is possible, however, to load a macro-enabled template as an add-in. All the functionality will then be available (Ribbon, keyboard shortcuts, macros, building blocks).
Save the document as a dotm file (template, macro-enabled)
Copy the file in the STARTUP folder. Word will then load it automatically.
For a "real" add-in that uses the same COM object model as VBA it's necessary to build software based on the IDTExtensibility2 interface. There are number of tools that use this, making things easier. Microsoft's VSTO (Visual Studio Tools for Office) is one that costs nothing.
Another alternative is to use the newer Java Script APIs for Office. These are, in the case of Word, incomplete as far as functionality for the object model is concerned (can't do everything the COM object model is capable of).

How to edit code for an excel add-in

I downloaded the Mini Calendar and Date Picker add-in from the Microsoft store and I would like to change a little bit of its functionality in VBA but cant seem to locate the add-in file anywhere . I activated the add-in and it works but it doesn't appear in the Active Application add-ins window under options so I don't know how to locate it. How can I go about this?
This is mentioned in the comments, but I'll officially answer as it's a common misconception that all Excel ADD-INS are written in VBA with an xlam file (particularly amongst financial Excel people who have just learned to write in VBA).
No. You cannot edit the code. It is not written in VBA and there is no xlam file, only a DLL file, which is much harder to interpret.
More "serious" add-ins, such as those found in Windows store, or are released by major software providers (SAP, Oracle, Microsoft) write their add-ins with C+, JavaScript or VB.Net. There's colossally more coding libraries in these languages than VBA, and the output of a DLL file makes it much harder for people to "steal" their code (as the OP intended to do, even if in a harmless nature).
So VBA enthusiasts won't be able to (easily) edit the code or learn from it.

How to move existing Outlook VBA code into an Outlook add-in?

I am trying to develop add-ins because my organization wants to move away from macros, due to the logistical tasks of deploying to thousands of users.
Is there a guide to repurpose existing VBA code into add-ins?
I want to be able to view/modify the source code.
Most helpful article so far:
https://blogs.msdn.microsoft.com/csharpfaq/2010/09/27/converting-a-vba-macro-to-c-4-0/ where they suggest "recording a macro in Office and then use the results in their code in VS".
I'm not aware of any VBA to VB.NET conversion tools, but the similarities are enough that you can copy and paste most code and correct the differences on the individual lines that prevent compilation. However it would be necessary to have a decent working knowledge of VB.NET in order to do this effectively.
I would though recommend that this task be considered a complete re-write, especially since you need to port it to an add-in project. The way you call your VBA methods may differ greatly depending on whether they are event or UI/Ribbon driven.
Also note that there is no macro recorder for Outlook.

To separate code and document in Office automation

I'm currently working on an vba project to help document developers do their work better and faster.
The tool is helpful during the developing, but however, it's no longer needed after the document is complete.
So, is there any ideas, about how to export a pure document without vba code automatically? Or shall I do this stupidly by opening vba and remove all of its code?
Further more, Is there any ways, to automatically apply vba code to an existing document?
You can create an add-in. Your VBA code lives in the add-in, but operates on your documents. The add-in can create a custom menu to run your various routines.

Using the Office Interop for Word and Outlook 2007 in VB.NET

I need interop in my programs to automate several functions in Word and Outlook. Does anyone know a good place to start. My goal is to kick off a mail merge, create several different files and save them accordingly, then e-mail the different files to different people based upon who needs what. Any help learning how to use the interop properly would be greatly appreciated.
I am currently using Visual Studio 2008 and Office 2007 and use vb.net to write my programs.
A good way to get started is to use the macro editor to record the steps you are trying to perform. You can take the generated macro code and modify it for your purposes to suit. Click on the names of functions and variables of which you do not know the purpose and hit "F1" to get context specific help.
Add COM references to Outlook 12.0 Object library and Word 12.0 Object library.
This web page really helped kick me off: http://support.microsoft.com/kb/316383
Then, by recording macros you'll expose a lot of the stuff you'll likely want to work with. Word of warning, however, is that not everything exposed in VBA (macros) is accessible within VB .NET. I don't know why this is, but I've actually had to construct and execute a macro from VB.NET, written in VBA, within Excel to accomplish something that seemed ridiculously easy if it weren't for the strange disconnect between the two.
Some good info on Mail Merge: http://support.microsoft.com/kb/258512
Here's an article with some basic steps to get you up and connected with Outlook's Interop: http://support.microsoft.com/kb/313787
Hope this helps. I'll keep an eye out for questions from you here--I'd say I know quite a bit when it comes to interop.
You might want to start here: http://msdn.microsoft.com/en-us/office/bb266408.aspx.
There are a number of tutorials.