How to save a word macro as an add-in - vba

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

Related

Export a Outlook form written in VBA

I recently wrote a form in VBA for Outlook and saved it to my personal form folder.
Now this form should get exported in a userfriendly fashion. What is the best practise here?
I know that you can go to File -> Export file... in VBA, but this seems to have caused some problems in the past and doesn't seem very intuitive to use both the frm and the frx files.
The form is supposed to be accessed by employees to book their holiday.
That is COM add-ins were invented for. They are designed to be installed on multiple machines and users. VBA macros are not designed for transferring the code - the infrastructure doesn't provide anything for moving solutions automatically like you could do in case of COM add-ins. You need have do that manually in VBA.
If you consider moving your solution to the add-in rails, see Walkthrough: Create your first VSTO Add-in for Outlook to get started quickly. You may choose VB.NET which has a similar syntax with VBA.

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

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.

Powerpoint Add-in: How to create downloadable add-in which modifies Ribbon and calls macros?

I create customised Office solutions for my organisation. To do this, I create Powerpoint/Excel templates which contain customisations I include by modifying the ribbon using Custom UI Editor - the buttons then call macros I wrote in VBA.
Right now, I am facing the problem that I need to keep rolling out new templates (and manually getting people to use it) whenever I want to fix bugs or update features. This is obviously not optimal.
Therefore, I wanted to build an Add-in which:
Modifies the ribbon in a similar way to Custom UI Editor
Can allow me to call VBA macros
Can be updated via the internet
However, (definitely because I'm new to this) the advice out there seems a little vague.
Is it possible to do what I am asking?
Microsoft has 3 different technologies that are all called add-ins. The one you're familiar with is the original VBA-based add-in. That technology can fulfill #2 on your list. However, there is no simple way to directly modify the Ribbon using VBA. It might be possible to update from the Internet, but that would not be an easy project to program.
The second technology is called COM. COM add-ins are most often written in C# or Visual Basic (similar to, but not identical with, VBA) in Visual Studio. COM add-ins can modify the Ribbon and can call VBA macros. Updating from the Internet would still be a more complex problem. Customize the Office Fluent ribbon by using a managed COM add-in
The third type of add-in is the JavaScript add-in technology that Microsoft is currently hyping as the next big thing. There are some UI elements they can manipulate, but not full-scale Ribbon mods. They can't run VBA macros. But they are update-able from the Internet. Understanding the Office JavaScript API

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.

Fragility of using Excel Object Library in Visual Basic

A bit of preface: this project, while technically homework, is completely under my 5-man team's control. We came up with the project, defined the scope, and exercise full creative control. So it's not traditional homework, it's equivalent to a senior project.
One of the outputs of the system I'm developing should be very similar to a well formatted Excel spreadsheet. We could create (or find) a graphics library and handle the printing in our own code... but ultimately we feel that an Excel spreadsheet file will be more portable. As the user can open it up in Excel, edit it, e-mail it, etc.
Accessing Excel programatically seems simple enough (i.e: http://support.microsoft.com/kb/302094)
But my question is: what happens when "Office 2013" comes out, and the user removes Office 2010 and installs 2013?
I won't be around to maintain this project... and I'd hate to force someone into opening up my code just to reference the Excel 13.0 COM.
I'll be using incredibly basic functions of the API.
So long as I can read-and-write to a range of cells, and adjust the interior color of cells, my code will work.
In general, how can I make my VB.Net code access whatever Microsoft Excel API is available on the target system? (Including future Excel APIs.)
I recommend first developing using the Excel PIA (Primary Interop Assemblies) so you get autocomplete and online help in Visual Studio.
Once your program is complete, I recommend switching to late-binding before publishing, so your EXE works with different versions of Excel.
Develop first using the current Excel PIA until it works as you
want (Google "Excel PIA" to download the assemblies)
When your program is complete, add Option Strict Off to the top of the modules that use Excel objects
Replace all Excel PIA classes with Object e.g.Dim xls As Excel.Application becomesDim xls As Object
Replace xls = New Excel.Applicationwith xls = CreateObject("Excel.Application")
Remove the Excel PIA reference and tidy up