+ Reply to Thread
Results 1 to 4 of 4

Updating VBA code without replacing the entire workbook.

  1. #1
    Registered User
    Join Date
    10-02-2022
    Location
    Tucson
    MS-Off Ver
    Varies
    Posts
    13

    Updating VBA code without replacing the entire workbook.

    I have a few workbooks containing thousands of lines of code that I have distributed to my organization. All of the workbooks contain user forms through which various people within my organization are able to manipulate data (this includes loading data from outside the immediate workbook). However, whenever I make changes/updates to the VBA code, I either have to

    1) export the data from the existing file, copy the new file to the directory, then import it into the new file with the updated code, or
    2) manually copy the code into the existing file

    Is there an easy way to update VBA code in a workbook without changing anything else whatsoever, as if I were simply updating a piece of software?

    Thanks

  2. #2
    Registered User
    Join Date
    04-19-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    O365, Win10 and Mac
    Posts
    47

    Re: Updating VBA code without replacing the entire workbook.

    Create an addin (xlam) instead. That will contain only the code. The data can then be stored in a normal xlsx file. There's lots of info about creating addins on the web, for example https://trumpexcel.com/excel-add-in/

  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,909

    Re: Updating VBA code without replacing the entire workbook.

    If it's a one off you could use something like to to import the updated modules

    https://www.rondebruin.nl/win/s9/win002.htm

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Updating VBA code without replacing the entire workbook.

    Hi there,

    See if the following approach gets you moving in the right direction - it requires a Reference to be set to "Microsoft Visual Basic for Applications Extensibility 5.3".

    Use the following code in your master workbook to export all of its VBA code to a shared directory (e.g. H:\VBA Modules):

    Please Login or Register  to view this content.


    Create a VBA CodeModule named M99_ImportVBA in each of the User workbooks whose VBA you wish to update regularly, and insert the following code into it:

    Please Login or Register  to view this content.


    Finally, insert the following code into the "ThisWorkbook" VBA CodeModule:

    Please Login or Register  to view this content.

    Using the above approach means that your updated VBA CodeModules need to be exported only to the shared folder. Each time a User workbook is opened, all of its VBA CodeModules will be deleted, and those from the shared folder will be imported to replace them.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Last edited by Greg M; 12-03-2022 at 08:47 PM. Reason: Original version was posted accidentally

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Apply code to entire workbook.
    By kgall89 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-26-2018, 08:49 AM
  2. Replacing Hyperlinks in an Entire Workbook
    By js0873 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-27-2017, 01:32 PM
  3. Updating Current Workbook with New Version Via Code?
    By CraigsWorld in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-21-2016, 02:53 AM
  4. New to VBA - Problem applying code to the entire workbook
    By itobon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2016, 01:46 PM
  5. VBA code for Count if funtion for entire workbook
    By VINOTHBASKRAN in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-13-2014, 05:07 AM
  6. Code runs on entire workbook...need it to only run on one worksheet
    By jrobertson2403 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-28-2013, 04:50 PM
  7. adding data to another workbook (replacing entire record if value in cell A matches)
    By ecc34_11 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2011, 08:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1