VBA code import

Go To StackoverFlow.com


I have a VBA project I am doing in excel. I will have many workbooks that will use the same code and I do not want to have to copy the code to all the workbooks if I make a change. Is there anyway to have the code in one central place and then have all the workbooks access that code?

2012-04-03 21:14
by DasPete
Possible duplicate: http://stackoverflow.com/questions/7047467/packaging-and-reusing-vba-code-in-exce - Donald Byrd 2012-04-03 21:24
I suspect solution 1 from Siddharth's answer will be your best option. However, this recent answer of mine shows how to run macros in one workbook against other workbooks - Tony Dallimore 2012-04-03 21:43


Yes, you have two options

1) Copy and paste the code in the Personal workbook.

More details here

Topic: Deploy your Excel macros from a central file

Link: http://office.microsoft.com/en-us/excel-help/deploy-your-excel-macros-from-a-central-file-HA001087296.aspx

2) Create an Add-In

Mode details here

Topic: Creating An XLA Add-In For Excel

Link: http://www.cpearson.com/excel/createaddin.aspx

Note: You can create Add-In in VBA as well as Visual Studio. For COM Add-Ins (created using Visual Studio), please refer to this link.

Topic: Office Development with Visual Studio (VSTO)

Link: http://msdn.microsoft.com/en-us/office/hh133430



2012-04-03 21:23
by Siddharth Rout
Siddharth, thanks for the suggestions, I don't think option one would work, as these workbooks will be used by multiple users. They are stored on a networked location and accessed by many different people. So from my understanding using my personal workbook would not solve the problem. Perhaps the Add-in is the better option. Another idea I had is to use a library. I am worried about updating code though. If I make a change to a library will it be changed in all the workbooks that reference it - DasPete 2012-04-04 12:48
Looks like I was a bit quick to respond, I played around a bit with the XLA add-ins. Looks like that could be the solution. Its too bad I don't have VSTO, I think that would be much better - DasPete 2012-04-04 13:49