Saving dotm to docm - embed macros in docm - vba

When I save a .dotm file with macros to a .docm file, the macro's aren't embedded in the .dotm file.
When I send the file to a colleague, he needs the .dotm, along with it to be able to use the macro's.
I want the code to be embedded in the .dotm, so it can be used as a standalone file.
Any way to do so?

I've seen this in cases where the .dotm is opened using a double click, and a new document is created from the .dotm by default. In this case the new document links to the macros in the template but does not copy them into the document. When you save the .dotm as a .docm, you're opening the original template and not working with a new document, right?

Related

.dotm opens differently from .docm

Sean W 2104 post Auto displaying form on opening a template file, dotm from explorer demonstrated how to show my form when my .docm document loads.
Timothy Rylatt's response to my vba word 2016 saveas document without changing module name suggested I render my .docm as .dotm template.
However, though my .docm shows my first form on startup, opening the .dotm does not. The .dotm only shows only the underlying document (that the forms populate).
So is it that my forms (and their VBA code) do not belong in the template document they fill? Do I instead need to load a template document that doesn't contain the forms? If so, do I create a dummy .docm document whose only purpose is to house the forms (and their VBA code?) If so, what do I do with the document from the dummy? Hide it? And what does my prospective client open?
You do not name your procedure Document_Open in your template but rather Document_New.
You are not opening the template, but rather creating a new document based on that template. Here is my writing on Auto Macros in templates.
You could also name the procedure AutoNew and place it in the another module of your template.

Save macro enabled document as new template

I created a Word 2010 template with macros and VBA code but then I amended one of the documents created from the template instead of the template and this included text boxes and drop down lists. How do I save the document as a new template with the macros maintained as well as the VBA and components such as text boxes etc. When I try and save the document as a .dotm file the option to place in Design Mode doesn't work and I have took the document out of Compatibility Mode.

Word formatting macro that calls another macro on a networked drive

I already have .docm files that have simple formatting macros embedded in them. The macros work. However I have 100+ different .docm files that use basically the same macro. Instead of changing the macros on all 100+ .docm files when I need to change a format, I would like to place the macro in a separate text file in a stable location on a network drive and have the macro code in each .docm file reference that text file.
I tried a Call Shell(AppName,1) statement where the AppName contains the path of the txt file, but the compiler won't work with a colon.
I researched creating a macro to change other macros embedded within each document, but was advised against it due to virus scanners.
It's not possible to run a macro from a text file, the way you imagine. (Cool idea, but a security risk, I think.)
Better would be to bring all the macros together in a single template (dotm), which you put in your STARTUP folder. When Word loads, it will load this template (with all its Ribbon customizations and macros) as an "add-in". (See also the Developer/Add-ins dialog box, which is where these can be managed.)
In this way, your code can be managed centrally - but you do have to explicitly open the template in order to make changes to the code. It can't be done just over the loaded add-in (that's only possible with Normal.dotm).
You can also have macros in this add-in template that you call from other macros. This can be done using the Applicaton.Run method.

can we run/install macro in without macro enabled files (pptx)?

I wrote some macro of PowerPoint. Now if I want to run these macros, I need to save my PowerPoint as pptm file. It is kind of matter, as I need to save the final file as pptx not pptm. Is there any way, I can install or run my macro to pptx files? I mean could I install my macro as an add-in, and it is working in pptx file.
If the way works, I can save my macro template powerpoint as pptx,
that is easier and more convenient.
Thanks,
You could create an application add-in which would allow the Public procedures within it to be available independently of the PowerPoint file(s) you are working on in any given session. You could optionally add controls to a custom ribbon tab by editing the fluent UI XML of the file (I have some articles on Stack Exchange to show you how) and link those to your macros.
To create an add-in, save the .pptm file as a .ppam file (the folder location will change accordingly). Then in PowerPoint, assuming you have the Developer tab enabled, you can click Add-Ins and load your add-in from there. If the Developer tab isn't enabled, you need to go into the Backstage by clicking File then Options to add add-is.
To make sure the add-in loads automatically each time PowerPoint starts you can add code to the Auto_Open macro to add the two relevent registry keys (add-in Path and AutoLoad flag) or do this manually using regedit.exe. If you are deploying to many machines, the add-in can be wrapped in a setup.exe or setup.msi package but that is another topic.
No I don't think so there is anyway to run macro without enabling it.
But Alternate solution can be to.
Save the main file as .pptx and you can have another file as .pptm you just need to add sub to open the .pptx or main file and perform the macro fuctions from there
In this way your macros file and .pptx are seperate and you can achieve what you are trying to do via the .pptm files.
Hope this helps.

runing the macro automatically to all existing and new documents

I have macro that create the footer with author and date, but I need this macro to automatically run to all word document (existing and the new document) just I open the word file which I saved before or the new one so there we find in document the macro that I create
save your macro file as a word addin file or put your macro in your personal.doc file and will be available for all files.
Store it in ThisDocument as OnCreate method ("Private Sub Document_NewDocument" if I remember well). Save it as Normal.dotm template, so it will automatically call it created document. You can also store it as OnOpen, and start your macro from removeing footer - this way all documents you open will get your footer.