Install a Macro With a Batch File - vba

I have a macro for Word that I would like to share with people, I want to create a batch file that installs the macro into word and assign it to a button.
Here is the batch file I have right now:
copy "Collapse.dotm" = "%appdata%\Microsoft\Word\STARTUP"
"%programfiles(x86)%\Microsoft Office\Office15\Winword.exe" /mCollapse
First the batch script copies the macro to the Word Startup folder. Then the script launches word, I ran the script and it is telling me it can't copy the macro.
EDIT: The error message was that Word could open up the template, I changed the extension to .dot instead of .dotm. With that change the script runs without errors, the template can be seen in the VBA Editor but doesn't create a macro.
EDIT 2: It creates a new project in the VBA that is unviewable though.

Related

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.

A copy of Excel Addin is created in My Documents after saving

I have an application (running in IBM Notes, using Lotusscript etc.) that create a new Excel object via OLE automation. In my app I create a new Workbook and saving it to a temporary folder (I am saving it as Excel Worksheet w/o macros -> type 52) so that the resuting file is sth. like that:
tmp_abc1234.xlsx
Then I open the file in Excel programmatically. I have an Excel Addin (filename is "Teamoffice.xlam" loaded where some macros reside I will trigger in the custom save actionbar button. In this save method I also call the save function:
Call ActiveWorkbook.Save
Call ThisWorkbook.Save
For some reason Excel creates a file named "Teamoffice.xlsm" in the "My Documents" folder. The file itself cannot be opened in Excel ("wrong file format error") - of course, it's an Addin!
This works well if I have only one Excel document open from my application. If I open a second (or more) I run into trouble: everytime I save on of those secondary opened (or newly created) documents Excel asks me if I want to overwrite that "Teamoffice.xlsm" file.
I added VBA code to ma macro that detects if this file is there and tries to delete it. With no luck of course, as the first instance of Excel is locking that file already. Overwriting the file when aswering the Excel-question dialog works though, but I don't want that question to appear.
Excel doesn't behave like that when using it stand-alone w/o OLE.
Several questions resulting from this behavior:
Why does Excel create this file? Can I stop it from doing so?
How can I delete the file even if Excel has a handle on it or
Can I tell Excel not tohave a handle on this file (if it's there) and let me kill it?
Can I suppress the question dialog and always say "yes, overwrite it"?
Office version is 2010 - and it makes me going nuts... so thanks in advance!
p.s.: I am not that VBA pro, so please be as detailed as you can effort :-)
I noticed that
ThisWorkbook.Save
was the reason. If I omit it no file is created. Strange that this saved the Addin file as xlsm file though.

How to Run VBA Macro in Word Doc after being Merged by external application

We are using the XML or Word ML format from Office 2003.
How do I get a macro to run after a MS Word ML document has been merged by another application (not Word) called SIMS by Capita.
How can I get the Macro to run after a merge, when the document is being previewed?
The Word-document doesn't know that it has been merged by another application. The only way that comes to my mind is to check for changes when the doc is opened and then run your macro.

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.