Passing an Auto_Open macro from one workbook to another - vba

I have to pass an Auto_Open macro from one Excel file to about one hundred other Excel files, which are generated automatically from R-script. I really don't know the VBA code.
At first I hoped that opening the file containing the macro and then opening the rest of the files will do the work, but unfortunately it didn't happen and I assume I have to pass the VBA code to all the files.
This macro does a little bit of formatting and limits the values in some cells. I found similar subject but I had problems with modifying VBA code to solve my problem. Is there any way to do simply copy that?

One solution would be to create a template containing the "Auto_Open" Macro and use this template to generate the hundreds of files with the "R-Script"

Related

How do I activate an unsaved workbook using VBA?

The goal of my code is to run an online report, copy the data from an exported excel file and paste it back to the main file, and then manipulate the data.
The trouble I'm running into now is copying the data from the exported excel file. The online report exports the excel file as an unsaved "Book1" with one "Sheet1" with the data in it. I cannot seem to activate the exported file so I can copy the sheet.
I've tried
Workbooks("Book1").Activate
As well as using a for loop to iterate through all open workbooks (there are only 2 open workbooks, but the for loop only loops once - telling me that it isn't looping through the unsaved workbook).
Any help would be greatly appreciated. Happy to clarify any questions as well.
Thanks

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.

Loading Set Macro's and Removing Set Macros

When I open Excel, automatically a workbook is loaded containing macros. I think a binary file? or in a personal macro set? How can I edit this? How do I stop these from loading and perhaps load other general macros instead?
My purpose is to load my most common macros across any workbook at any time so I don't have to go hunting for them each time.

VBA code in a template

In a Word template I have a command button with VBA code behind it.
The problem is that the code gets lost when a document is created using that template. The button is still visible, but the VBA code behind it disappears for some reason. This causes the button just to be clickable without performing any action.
The documents are saved in .docx format.
How can I 'glue' the button to its code so it doesn't get lost ?
First, make sure your VBA code is saved in the .dotm template that you make available to everyone (and not in your personal normal.dot/dotm template — this is only available on your machine).
Then, make sure the documents generated from the template are saved as .docm (not .docx).
.docx documents cannot contain VBA code. Anything saved in .dotx or .docx format will, by definition, lose all VBA code.
In a comment you say
"this doenst matter, as the document is just used for the macro."
This is incorrect; it does very much matter. .docx documents can't "be used for" macros because they can't contain macros.
For the macro to be always available, you need to store the macro in the normal template.
For example when recording a macro, select All Documents (Normal.dot) on Store Macro in.

How to Make a VBA Excel Program Work on Other Excel Documents?

I'm very new with VBA Excel and i only know the things as far as i need for this report formatting task. My code is almost completed, but what i wonder is, how can i make my program work on several documents?
I mean, i want to choose an excel file via my program, then i want to start the process of report formatting. Then maybe user need to format another document, i want my program to be able to format that document too. how can i achieve that?
Thanks in Advance
Timur
The way I am currently doing this is by creating an Excel add-in. To do this, place your macros and forms into a new, empty Excel workbook and save as a .xlam document.
To use the macros, open the your Excel file and the add-in. To open the add-in automatically, save it to "C:\Program Files\Microsoft Office\Office12\XLSTART" (Vista).
You can even create a custom ribbon for your add-in using the Custom UI Editor for Microsoft Office http://msdn.microsoft.com/en-us/library/office/ee691832(v=office.14).aspx (The download link is at the end of the instructions)