Sharing VBA code stored in PERSONAL.XLSB - vba

I have written some VBA for Excel which I'm sharing with colleagues by manually exporting the .BAS files from which they manually import.
Having just discovered I can use VBA to automate this process myself - see here at Ron de Bruin & and here at Chip Pearson - so it seems to me I can set up my colleagues machines to check for any changes when Excel opens and update the modules in their PERSONAL.XLSB file.
QUESTION: My questions is whether there are any pitfalls in doing this that I might not be aware? (Aside from the obviously need to keep the code-hub secure)
I've completed most of the development now (after 75 increments) and changes are only about once a month so the overhead of updates are bearable. However it may be possible to distribute code in a similar way.
BTW: I search the Stack Overflow for similar questions, the closest I got was - Replacement of old modules with updated ones in PERSONAL.XLSB
Thanks.

Related

After debugging VBA code, excel filesize is inexplicably large

The problem
Although one might assume this is a de rigeur problem with a mismanaged workbook, please hear me out. I'm working with a relatively modest (80-100kb) excel file. It has minimal formatting, very few formulas, and it's vba code doesn't do anything too fancy. I've been working with vba for a few months now and have had this problem exactly once before. As this tool will be used in producing reports for a while to come, and as I've limited time, I'd rather not rebuild the whole thing or turn in an unwieldy project.
Details
My code loops through several dozen 200+kb .xls files using Workbooks.Open method and grabs 1-2 values depending on what it's opened. It's been working through over a half dozen iterations with no change in size. In my latest version it's balloned from 100kb to 10mb. No tabs have been added, I've looked extensively for all sorts of formatting and other traditional pitfalls—it's not my first rodeo in that respect. I am new-ish to vba though, and so often step through code and have to pause or stop debugging before resuming to correct syntax. Sometimes this will happen before any Workbooks.Close method.
I think, inexplicably, during some combination of saves/crashes/debugging, excel has 'saved' some of the opened workbooks in this file's memory. It gets weirder: if I copy all of my worksheets, as well as my code, to a new workbook, the file size falls back down to 100kb or so. I've had this problem once before. Using a 20kb workbook I was trying to pull values from a 135mb workbook; after one save I noticed that my workbook was now 135mb and change, and I was only able to get it back down to 20kb by copying everything one sheet at a time to a new workbook. Does anyone know what's going on?
Attempting to google this produces dozens of pages on extraneous formatting, formulas, and VBA code unrelated to my issue.
I could post pseudo-code if it would be useful to see, but I'm pretty sure it wouldn't be too enlightening, and that my problem is some memory issue that occurs between .Open and .Close methods.
Edit: after looking through some of the workbooks that I'm opening, quite a few of them are 'around' 10mb. It seems suspicious to me that my tool would increase in size by about as much as one of the .xlsx files I'm opening.

Excel Personal Worksheet VBA Module's won't allow me to view code

My personal workbook (PERSONAL.xlsm) has stopped allowing me to view the code or any details of the modules I have saved there. It also will not allow me to run any of the Macros it once included. I don't know if they got deleted or are hiding somewhere (but I am hoping it is the later). I have not done anything out of the ordinary. Before this issue was happening all I had done with excel today was run one of these macros (without issue), make an edit to include the solver in a macro, and save it.
In addition to this problem there are a few others that seem to accompany it:
Occasionally when I close excel without saving a file, excel crashes.
If I attempt to record a macro (either in the Personal Workbook or to
another location) one of the following happens:
a. Excel crashes.
b. Excel gives me an Invalid Name Error (despite the name being perfectly valid.
It is worth noting that macros not saved in the Personal Workbook work just fine. I am very stumped and cannot find a solution to this problem anywhere. I have tried the obvious (rebooting my computer), the not so obvious (restoring previous versions of files), and the weird (disabling and enabling random things in the excel options section). Please, if you have a solution let me know!
Thank you in advance, all and any suggestions are appreciated!
I had a similar problem a while ago. I had to:
close Excel
re-name PERSONAL.xlsm to something else (like temp.xlsm)
open Excel and verify it does not "see" or attempt to open PERSONAL
create a new PERSONAL.xlsm
copy all VBA from temp.xlsm to the new PERSONAL.xlsm
Can't comment yet, so i apologize in advance.
It is definitely Excel at fault, it happens to me so often (on big files including VBA) that my before_save saves a copy of the file with time in its name, and all module's, userform's, sheet's code as *.frm, *.cls, *.bas.
I usually can also open corrupt files by holding SHIFT key (force designer mode) and then copy manually stuff.

Excel VBA Remove Add-In Reference, Close Add-In and Remove From VBA Project

My overall setup is quite involved, so here is my attempt to pin-point the precise part that I'm stuck on.
For whatever it's worth, I will have much respect for whoever can figure this out. I think that the solution requires an esoteric understanding of Excel Add-Ins.
The Background:
Here is the relevant universe of files that I am dealing with:
Filepath_2\UI_2.xlsm
Filepath_1\CI_1.xlsm
Filepath_1\AI_1.xlam
Filepath_2\CI_2.xlsm
Filepath_2\AI_2.xlam
Filepath_2\UI_2.xlsm is the file that is running the VBA to accomplish the desired file operations on/in the other four aforementioned files.
Filepath_1\CI_1.xlsm contains a reference to Filepath_1\AI_1.xlam.
My goal is to...
Copy Filepath_1\AI_1.xlam to Filepath_2\AI_2.xlam
Copy Filepath_1\CI_1.xlsm to Filepath_2\CI_2.xlsm
Open Filepath_2\AI_2.xlam
Open Filepath_2\CI_2.xlsm
Remove, from Filepath_2\CI_2.xlsm, the reference to Filepath_1\AI_1.xlam
Set, in Filepath_2\CI_2.xlsm, a reference to Filepath_2\AI_2.xlam
... handle business in Filepath_2\CI_2.xlsm ...
Close and delete Filepath_2\CI_2.xlsm and Filepath_2\AI_2.xlam
... and, I am able to accomplish all of the above save for one minor snafu:
The VBA project for Filepath_1\AI_1.xlam is opened upon opening Filepath_2\CI_2.xlsm and I cannot figure out any way to close it.
The Question:
What is the required VBA code to close the VBA project for Filepath_1\AI_1.xlam?
It is worth mentioning that my current inability to close that VBA project is not adversely affecting anything for the time being, so this is really a matter of control and process cleanliness for the longer term. I simply do not want a stray VBA project remaining open.
I can be somewhat flexible about the order of file operations that I mentioned above, as long as it culminates in the last three steps of it:
Set, in Filepath_2\CI_2.xlsm, a reference to Filepath_2\AI_2.xlam
... handle business in Filepath_2\CI_2.xlsm ...
Close and delete Filepath_2\CI_2.xlsm and Filepath_2\AI_2.xlam
Just one pre-emptive note to save everyone's time: Please do not suggest changes to the current suite of filepaths as the desired solution cannot interfere with the rest of what needs to be done. This file setup is part of a much larger situation that handles business in secondary copies of master files, after which the secondary copies must be closed and deleted.
This is my first question on Stack Overflow. I've attempted to make it self-contained as well as be free of actual VBA code since I don't think that someone who knows the solution I've asked for needs my own code to provide the few lines of code that most likely comprises the solution.
If you think you can help me out but need more information or some actual code, please let me know. Thanks!
Edit:
Thanks for your comments so far. Allow me to clarify further, and I think that this really gets to the crux of the matter. I've also edited my original question to correct some minor inaccuracies.
I earlier misstated one of the steps above as:
Close Filepath_1\AI_1.xlam
I don't attempt to do this anywhere.
Once I open Filepath_2\CI_2.xlsm, it has a reference to and shows the VBA project for Filepath_1\AI_1.xlam; the problem is that Excel does not, at any point, recognize Filepath_1\AI_1.xlam as an open file.
In fact, even if I open Filepath_1\AI_1.xlam by its mere self (without opening up any files that reference it), Excel does not recognize it as an open file, although it opens up the VBA project for the file. By 'recognize', I mean that if I use a For Each loop to cycle through the open add-ins (or open workbooks), Filepath_1\AI_1.xlam never shows up.
What I'm trying to do seems like it should be quite doable, and yet I just cannot find any way of doing it that doesn't leave that stray VBA project open...

VBA Ignore Excel cannot complete this task with available resources

I'm writing a VBA code that will run everything after I leave the office.
The macro works fine, the problems is that sometimes (more often than I'd like) I get the message:
Excel cannot complete this task with the available resources. Choose less data or close other applications. Excel cannot complete this task with the available resources. Choose less data or close other applications. Continue without Undo?
I just click OK and the code runs fine, but I have do click the OK manually,
I've already tried the
Application.DisplayAlerts = False
but this doesn't work.
Does anyone know if I can't make excel "overpass" this problem?
Thank you in advanced
I believe "Continue without Undo" means Excel is temporarily clearing the RAM it uses to track undo levels and then (it seems) your macro has the resources it needs to complete the process.
Take a look at what your macro is doing to use so much RAM: Is there a way to modify it so that less RAM is required? There are several options for this listed here:
How to clear memory to prevent "out of memory error" in excel vba?
Second option to fix this might be adding RAM to your machine, but it will not fix the cause of the error.
Third, if you want to risk a registry edit and reduced or eliminated undo levels in Excel, you might be able to prevent this error by reducing the number of undo levels (http://support.microsoft.com/kb/211922).

Is there a standard process to save Excel File Formatting/Settings into an Object?

It could be cumbersome at times to maitain Excel Workbook's formatting/settings when heavy backend, front end work loads are done. At times (even frequently) workbooks were crashed. But I can't recall what the code or process was to avoid this happening due to the formatting. What I am clear is that before any data retrieval, processing took place in the workbook, I saved the Workbook's formatting/settings into an object. Once everything was completed, that object was called to restore. It was most probably one of the custom/user written classes.
That code was very handy when working with Workbooks to manage certain company standards/Logos/Colour Pallete/formatting/protection settings/code settings and so on.
So I just want to ask if anyone in the community have come across such process? I searched online and disappointing enough I am unable to find anything near - else I have really lost my wits on key-word search ;)
PS: This is not my home work or work. So please throw some light.
If you are talking about creating spreadsheets that conform to your branding standards, why don't you just create a template file:
http://office.microsoft.com/en-us/excel-help/save-a-workbook-or-worksheet-as-a-template-HA010218874.aspx