+ Reply to Thread
Results 1 to 11 of 11

Changing workbook code via vba

  1. #1
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Changing workbook code via vba

    Hello all,

    I have code for my sheets (e.g Sheet1(Main)) that runs all the activation and change events etc. I also have various modules.

    I have code that will modify the modules: for example, this follow code deletes a module:

    Please Login or Register  to view this content.
    However, I don't know how to manipulate subroutines within the sheet module.

    In principle, I would like to locate a string within a Sub, and change it. Or, if I have to change the entire sheet module without affecting the sheet itself.

    How can this be done - can anyone point me in the right direction. I look at CPearson stuff but it didnt seem to provide this particular answer.

    Cheers

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Changing workbook code via vba

    Hi Journeyman3000,

    See the attached file and/or code in post #3 of the following thread. If it doesn't solve your problem, the references may point you in the right direction. http://www.excelforum.com/excel-prog...de-in-vba.html

    Lewis

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Changing workbook code via vba

    Why do you want to do this?
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Re: Changing workbook code via vba

    Thank you for your responses. I was kinda hoping for a shorter solution in which I could provide the sheetname, locate the string in the VBE editor and change it. I'll search through the solution and see if I can find it there. cheers

    Norrie: I want to do it becuase I've distributed the workbook to mulitple people, and I need to update the code in each. I can do this by looping through each book, looking for the correct worksheet, updating the VBE ect. In this case, it's just a single string. Cheers

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Changing workbook code via vba

    Why not use an add-in?

  6. #6
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Re: Changing workbook code via vba

    I don't know what add-in to use, and I beleive it should be acheviable with code.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Changing workbook code via vba

    Hi Journeyman,

    Try using the forum search with "VBComponent" - I've found several entries that seem pertinent to your task
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Changing workbook code via vba

    Hi, Journeyman3000,

    I´d have a read at parameters and pass the information you want to change via parameter, a list in a worksheet, a name in the name manager, a text file rather than changing code.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Changing workbook code via vba

    The best way to update the modules in others workbooks is to create exported files of the modules and have them run a routine that deletes the existing module and imports the files (exports) that you provide.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Changing workbook code via vba

    You would create the add-in, distribute it, edit it, redistribute it etc.

    Using code to create/change code can be done but can cause problems.

    For example security settings would need to be changed (lowered).

    PS If it's just a single string why not store it somewhere instead of hard-coding it?

  11. #11
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Re: Changing workbook code via vba

    Thank you all for for advice.

    Using addins is a good idea, but for this particular excercise I needed to change the code in the VBE for Sheet1. It turns out there are several locations that needed updates so I can pretty much use the same code, although lesson learned for the future. I found the following code, and modified it slightly and it works as required.

    Please Login or Register  to view this content.
    Thanks to all who provided advice.

    Cheers

+ 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] Auto-Closing of Workbook Keeping me from Changing VBA Code?
    By dac5039 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-17-2014, 10:24 PM
  2. [SOLVED] Need code for changing workbook on time ?
    By black7 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-20-2013, 05:08 PM
  3. changing code from New worksheet to new workbook then new sheets.
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2012, 12:52 PM
  4. Changing Code To Modify Entire Workbook
    By sktyrhrtout in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-08-2008, 07:28 PM
  5. Changing Workbook Code Using a Macro
    By jamesryan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-07-2008, 04:05 AM

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