Auto Update VBA Forms and Modules Online - vba

Currently I am creating VBA Macros for Excel and recently have started using UserForms.
However, the dilemma is once the Excel File is deployed to the users, there comes a time that I need to update the code on the UserForms or Modules.
What I would like to know is: Is it possible to automatically update these UserForms or Modules by having Excel go online and download the updated UserForms and Modules like as patcher or something?
I got this idea from this link

I think you will find this thread useful, it suggests ways to update an Excel add-in. I'd go down the route of getting the Excel file to update a separate small bootstrap file, that then handles any necessary update (suggestion by Robin Hammond on the thread).

Where I work, we solved this dilemma by storing the workbook on the network as a read-only file which is always used as the point of entry.
If the user wants to save it, they can do so on their own machine. If you want to update the file, you just switch out the current one, since it will not be locked (due to being read-only). Obviously, this approach only works if you have a shared network, but I think it's a rather simple to implement approach.

Related

Use VBA in some form to edit or create more VBA code for a file that will be distributed

So whilst I tried to make the title as clear as possible I will expand on it here.
I am trying to create a new macro, the data for that macro will come from Pastebin, this file would be distributed to many people in different countries. Thus my goal would be to be able to modify or update macros in one shape or form, I can do an easy test to check if there are updates but could not figure out how to modify a macro, I would happily create a new excel workbook temporarily that has these macros or possibly create a VBScript and that creates a macro, not sure of the best method to do this.
What I have done so far, form tons of searching how to programmatically moidfy macros is form the website cpearson
However this needs the modification of security which has to be done one each computer that will use this file and that is just not a possibility.
If you need more clarification on the question feel free to drop a comment, (might reply tomorrow)
Any suggestions on how to modify or import macros or workarounds to achieve the desired effect would be amazing.
This sounds like something I made a couple of years ago. (It's company property now so I can't redistribute it). Here is the general idea with PasteBin as source:
You can do this by creating a VBA-injector and placing the module name in the top of the Pastebin.
changesMadeDate|
Modulename1 updateDate1|
//your code here
|Modulename2 updateDate2|
//and so on
If you are working with just Modules, UserForms and Classes this is pretty doable but stay away from Worksheetcode because then you can't use the remove and add method but would instead have to rewrite the sheet code with SendKeys. (Unreliable)
What you need to do (using modules as example):
Create a Pastebin that contains all the modules as described above.
Create a methods to split the Pastebin data and save each module locally as moduleName + ".bas" using FSO.
Remove and add modules to the current project.
You can use this to also create a updateDate for each module and only update those that are newer. Just add a updateDate after Modulename in the Pastebin.
You can distribute just the VBA injector and everyone can use the modules after running the update. Also add changesMadeDate before the first module name in Pastebin and you can create a Workbook_open event that checks it to know if to run the update at all.
If you exceed the Pastebin char limit then just do:
ModuleName1 pastebinlink1|
ModuleName2 pastebinlink2|
Then go from there. Using a shared textfile would probably work better though.
Edit: You could also delete all but injector modules. Then add empty modules and use VBIDE.VBComponent.CodeModule then write into them, but I prefer the first way.

Is it possible to create Excel VBA Code Library that several workbooks share?

I have several workbooks that have similar and reused VBA code sometimes I need to update the code and I would like to do this in one place instead of in 20 different workbooks is this possible?
If not is there a way to copy all the macros from one workbook to all the others after a change has been made?
Yes, you can reference other workbooks from VBA. Might be easiest to put it in an addin though.
If you are using class modules, then you can only set them as either private or public not createable (something like that). Obviously they'll need to be public, but you can get around the inability to create them by building simple helper functions in a normal module that do nothing other than create a new instance of the class and return it.
It is possible, yes.
This answer on SU mentions one possibility that is explored more in-depth in this support article.
If you find yourself recreating the same macros, you can copy those
macros to a special workbook called Personal.xlsb that is saved on
your computer.
By default, when you create a macro in Excel, the macro works only in
the workbook that contains it. This behavior is okay as long as you
don’t need to use that macro in other workbooks. Any macros that you
store in your personal workbook on a computer become available to you
in any workbook whenever you start Excel on that same computer.
In short: record a macro and choose to save it in Personal Macro Workbook. Save and exit, then re-open Excel. Go to the View-tab and click unhide.
The support article gives a more detailed step-by-step.
Sure is possible,
the two ways that I know are:
copy your macros on Personal.xlsb (like Vegard wrote) or (it's my usually case because I've also my custom Ribbon to play all my custom cmd) you can open a new excel file, write in this file all your macro/function/class.... and then save it as xlam file.
After you need to go on excel option, add components and choice the xlam file before created.
Tips, in the xlam file use a specific macro names and not macro1, macro2,.... because into your next files will be easy to create more macro and use the same name is usually..
I'll add my answer based on experience as it seems the ones given are all (unspoken) focused on being "free".
I started out using a workbook as my code library (as suggested above), but every time I made an adjustement or improvement to those code snippets, I had to go back to the other workbook and update it etc. This got old fast.
Once I started developing a bit more professionally, it made sense to invest in a tool to manage my code.
I use MZTools which also comes highly recommended by various Excel MVPs such as Ken Puls, Ro Bovey, etc. but there are other ones out there. Usually these tools also provide addtional functionalities that are useful to a developer. Invest a few bucks if you want to save your self from a headache.

Distribute updated Excel VBA code to Multiple End-Users

I've created an Excel 2010 workbook with a number of sheets. VBA code that performs various data manipulations is in a couple of modules, and also attached to a couple of forms. The workbook is being distributed to a couple dozen people in different departments to use. They will be populating their workbook with their own department-specific data.
If I need to distribute an update to the code (either a bug fix or some new function), how can that be done? I don't want the users to have to reenter or copy/paste all their data into the 'new' workbook - I'm essentially looking for a method to update the VBA Project that's inside their existing workbook.
You could create an additional helper workbook Help.xlsm, that has its file attributes set to read-only.
Move all the vba code, that you might need to change in the future, into Help.xlsm
The file that you distribute then needs a reference adding to Help.xlsm
Now in the future changes can be made to Help.xlsm and they should appear in the client's files.
Above assumes all your customers are on the same network so that you can store Help.xlsm somewhere that is accessible to all their files.
This article explains it better than me:
http://www.excelguru.ca/content.php?152-Deploying-Add-ins-in-a-Network-Environment
You would need to export the modules and forms and manually import them into the existing workbooks. I used to have to do this for some projects i worked on.
Alternatively you would need to write some helper code to import the old data into a newly published workbook, but this depends on how the data is organised of course. Again this is another approach I took for a different project.
You can also do this procedurally. Ive used this for small patches.
http://www.cpearson.com/excel/vbe.aspx

Accessing External Modules

I have about 8 different workbooks that all have the same modules in them. Unfortunately, the workbooks need to be separate. I have four modules in each workbook. Whenever someone finds a problem with the workbook such as an error I did not catch originally in the code, I have to make the correction to all of the workbooks. Presently, I make the correction in one of the modules, export it, and then delete the bad module from the other workbooks and import the corrected module(s). This is time consuming and I am hoping to find a way to either quickly import the updated modules or access the modules from a centralized location on the network drive. Is this possible?
I have scoured the internet but either I am not typing in the correct search or no one seems to have this issue. Thanks
If all of these workbooks reside on your machine and are used mostly by you, then you could put the macros in your personal.xls file and have only one copy on any of the various spreadsheets. There's a good tutorial about the personal.xls on Ron de Briun's site:
http://www.rondebruin.nl/win/personal.htm
Part of your question suggests that the workbooks might reside on other computers and you are then updating and distributing the new versions. If that is the case you might try using the method suggested by Charles Williams in this Stack Overflow question:
How to get VBA excel addin .xlam to replace itself by a remote updated .xlam?
Then you would simply create a shared add-in and replace the file in one location referenced by the xla/xlam. Ozgrid has a decent primer on creating add-ins:
http://www.ozgrid.com/VBA/excel-add-in-create.htm
Hope that at least some of this helps with your problem.

Manipulate Excel workbooks programmatically

I have an Excel workbook that I want to use as a template. It has several worksheets setup, one that produces the pretty graphs and summarizes the numbers. Sheet 1 needs to be populated with data that is generated by another program. The data comes in a tab delimited file.
Currently the user imports the tab delimited file into a new Workbook, selects all and copies. Then goes to the template and pastes the data into sheet1.
This is a large amount of data, 269 columns and over 135,000 rows. It’s a cumbersome process and the users are not experienced Excel users. All they really want is the pretty graphs.
I would like to add a step after the program that generates the data to programmatically automate the process the user currently must do manually.
Can anyone suggest the best method/programming language that could accomplish this?
POI is the answer. Look at the Apache website. You can use java to read the data and place it in cells. The examples are very easy.
You can can solve this, for example, by a simple VBA macro. Just use the macro recorder to record the steps the user does manually now, this will give you something to start with (you probably will have to add a function to let the user choose the import file).
You said you have some data generated by another program. What kind of program? A program that you have developed by yourself and where you can add the excel-import functionality? Or a third party program with a GUI that cannot be automated easily?
And if you really want to create an external program for this task - choose whatever programming lanuguage you like as long as it can use COM objects. In .NET, you have the option of using VSTO, but I would only suggest that for this task if you have already some experience with that (but than you would not ask this kind of question, I think :-))
Look here:
Create Excel (.XLS and .XLSX) file from C#
There's NPOI (.NET Framework version of POI) so that you can code in C# if you want.
If you use two workbooks - one for data and one for graphs - and don't update links automatically you can use a macro to get the data (maybe an ODBC connection if the file is in a format it can read - long shot) and then link the charts to the data workbook.
Use a macro to update the links and generate the charts and then send them out and hope no one updates the links.