Loading Set Macro's and Removing Set Macros - vba

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.

Related

Excel VBA requiring file extension for workbook reference in some systems

I have a simple excel VBA that is referring multiple files and copying information across to a master before processing. While building this on my own system a workbook reference (working perfectly fine) was written as:
Workbooks("key").Sheets("Sheet1").Range("A1:X57").Copy
Here key is a .xlsx file
While using this in another system this does not work and it explicitly requires the file extension in every call.
Workbooks("key.xlsx").Sheets("Sheet1").Range("A1:X57").Copy
It would not be extremely difficult for me to make this change although I wanted to understand why this is happening and can I define an Option (guessing!) that would not require me to do so?
Why is there difference in behaviour across systems while running the same script?
Any help would be much appreciated. For me this seems like VBA having a mind of its own.
If the key.xlsx file is saved on both systems, including the file extension when referring to the Workbook objects is the safer option because of Windows hide extensions setting:
The Workbooks Collection Object
If the hide extensions setting is not in effect (meaning that
extensions are indeed displayed in Windows), you must include the xls
extension when you reference a workbook in the Workbooks collection.
For example, if you have open a workbook named Book1.xls, you must use
Workbooks("Book1.xls").Activate
rather than
Workbooks("Book1").Activate
to refer to the Book1 workbook. The second line of code above, without
the xls extension, will fail with an error 9, Subscript Out Of Range,
because there is no workbook with the name Book1. If the hide
extensions setting is effect, you can omit the xls extension and use
either of the following lines of code.
Workbooks("Book1").Activate
Workbooks("Book1.xls").Activate
These lines of code assume that you do not have open both an unsaved
workbook with the name Book1 and a saved workbook with the name
Book1.xls. With the hide extensions setting enabled (so that
extensions are hidden in Windows), the two lines of code above are
functionally equivalent. As a matter of good programming practice, you
should always include the xls extension in a workbook name. This
ensures that you reference the correct workbook regardless of the
value of the hide extensions property.
More details from cpearson.com for File Extensions And Their Implications In VBA Coding

How do I Embed file in excel, use it and then embed new version again into excel workbook I'm creating a new Userform control for excel?

I'm creating a custom Usercontrol (Userform) for excel, the name is Virtual forms.
The control is storing data in external file that is created in the same folder where the workbook is (example: VFFile.vf).
How to embed this file into excel (maybe OLEObject? or is there some other solution?)
More info:
I created a Usercotrol (ActiveX control) for excel, which uses an external file with definitions (VFFile.vf). And now to avoid that the developer always has to define the filename where this file on his computer is, I would like to somehow incorporate the file into Excel (when he drops this control onto excel worksheet the control will also put this file into excel workbook). Is there a way to do this?
I continue to use an external file because it gives me the possibilities to use this control in other environments, not only VBA with Excel.
For example, I can use it also in Python, or C# or VB.net.
Thank you guys for your tips and directions.
Davor

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.

Passing an Auto_Open macro from one workbook to another

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"

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)