+ Reply to Thread
Results 1 to 17 of 17

Macro Code That Edits Other Macro Code In Workbook

  1. #1
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,146

    Macro Code That Edits Other Macro Code In Workbook

    Does anyone have a macro that searches all other macros in a workbook for a specific term and changes that term to something else the user has indicated by an Input Box entry ?

    I've looked online and located several examples but none of them work. ???

    Thanks

  2. #2
    Registered User
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2410
    Posts
    185

    Re: Macro Code That Edits Other Macro Code In Workbook

    Do you want to edit live macro code in your VBA project?
    Please descibe some more details.

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,146

    Re: Macro Code That Edits Other Macro Code In Workbook

    The process I am seeking is to replace all instances of a term with another term, throughout the workbook modules. This 'replace term' macro will utilize two Input Boxes ... one for the search term and a second indicating
    what term shall be used as a replacement.

    So ... the user clicks a command button and the first Input Box is shown requesting what term to search for throughout the modules. Then the second Input Box is displayed and this requests the term that will be used to
    replace the existing term when found.

  4. #4
    Registered User
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2410
    Posts
    185

    Re: Macro Code That Edits Other Macro Code In Workbook

    What is your 'term'?
    VBA keyoword, Variable name, number or Text...

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,146

    Re: Macro Code That Edits Other Macro Code In Workbook

    The term will be text.

  6. #6
    Registered User
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2410
    Posts
    185

    Re: Macro Code That Edits Other Macro Code In Workbook

    You can use variables, and apply user answers.
    Please Login or Register  to view this content.

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,454

    Re: Macro Code That Edits Other Macro Code In Workbook

    This will give you an idea...Credit to snb
    Set reference to "Microsoft Visual Basics For applications Extensibility" & Check the Box "Trust access to the VBA Project object module" in Macro Security settings...
    Place code in an external workbook...you can amend with input prompts...
    Please Login or Register  to view this content.
    Last edited by Sintek; 11-03-2024 at 08:19 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,146

    Re: Macro Code That Edits Other Macro Code In Workbook

    Sintek your code works very well with the regular modules. I tried editing the code so it would apply to the sheet level modules as well but without success.
    Any thoughts ?

    See amended code :

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2410
    Posts
    185

    Re: Macro Code That Edits Other Macro Code In Workbook

    Each sheet is vbext_ct_Document...
    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor MikeVol's Avatar
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    2021
    Posts
    411

    Re: Macro Code That Edits Other Macro Code In Workbook

    NOTE: As the original poster/owner, only you can mark your thread as SOLVED (Thread Tools above Post #1).
    You can say "Thanks" in your thread to everyone who offered to help you.
    You can also reward them by clicking * "Add Reputation" under their username on the left.
    With Regards, MikeVol.

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,454

    Re: Macro Code That Edits Other Macro Code In Workbook

    2 is for class modules...

    Please Login or Register  to view this content.
    Last edited by Sintek; 11-03-2024 at 10:43 AM.

  12. #12
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,146

    Re: Macro Code That Edits Other Macro Code In Workbook

    Thanks for everyone's assistance.

  13. #13
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,454

    Re: Macro Code That Edits Other Macro Code In Workbook

    Glad you got it sorted...Tx for rep +

  14. #14
    Valued Forum Contributor MikeVol's Avatar
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    2021
    Posts
    411

    Re: Macro Code That Edits Other Macro Code In Workbook

    It was my pleasure to help you. Thanks for rep - Up!

  15. #15
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,146

    Re: Macro Code That Edits Other Macro Code In Workbook

    I did some editing to better suit my needs. Here is the code for others to enjoy ...

    Please Login or Register  to view this content.

  16. #16
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,454

    Re: Macro Code That Edits Other Macro Code In Workbook

    Just be careful...That snippet change to activeworkbook wil effect the Main macro too...Might have to add a snippet to exclude...
    Place it it a stand alone module and include ... i.e.
    Please Login or Register  to view this content.
    Last edited by Sintek; 11-03-2024 at 02:18 PM.

  17. #17
    Registered User
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2410
    Posts
    185

    Re: Macro Code That Edits Other Macro Code In Workbook

    I believe this method carries significant risk.
    Please be very cautious when deploying.

+ 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. Help: Macro to run another macro/code on all worksheets within same workbook
    By ahmedfikry in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-17-2021, 12:34 PM
  2. Save as active workbook with module & macro code in (this workbook)
    By nisshaheen76 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2019, 10:24 AM
  3. [SOLVED] Code to create Macro Button and Assigning Macro code
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2014, 11:30 AM
  4. [SOLVED] Copying Macro Code into the Personal Macro Workbook
    By tullybcfc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-21-2013, 07:59 AM
  5. [SOLVED] Macro to Use Multiple Cells in Workbook to Create Code Cell in another Workbook
    By michaelpair in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-26-2013, 10:33 AM
  6. VB Excel Macro That Edits Itself Code
    By ashleys.nl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2011, 08:15 AM
  7. Add vb code to a new workbook using a macro
    By Alagard in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-17-2010, 11:40 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