+ Reply to Thread
Results 1 to 7 of 7

Macro to edit macro

  1. #1
    Registered User
    Join Date
    06-30-2019
    Location
    Cardiff, Wales
    MS-Off Ver
    Office 2016
    Posts
    10

    Macro to edit macro

    Hi,

    I need to create a macro that can be used to update the vba in an existing macro. It would need to search the current code for a specific line and then replace it with the new line. Also, the vba editor in the workbook is password protected, so the new macro would need to unlock the editor and lock it again (with the original password) after updating the code.

    Is anybody able to help please?

    Thanks

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Macro to edit macro

    You'll need to give us bit more detail...

    However, first you'll need to allow code to access VBA project object model.
    Developer tab -> Code ->Macro Security. Tick "Trust Access..." found under Developer Macro Settings.

    Then you'd have access to VBA project objects to manipulate via code.

    Have a read of links.
    https://www.rondebruin.nl/win/s9/win002.htm
    http://www.cpearson.com/excel/vbe.aspx
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    06-30-2019
    Location
    Cardiff, Wales
    MS-Off Ver
    Office 2016
    Posts
    10

    Re: Macro to edit macro

    Hi CK76, thanks for getting back to me. I created a workbook with numerous macros in as a tool for my job. This workbook has then been copied over 150 times with individual records saved in each. However, I realised one of the macros I built in the original template, has a line missing so I'm looking to create a new macro which I can then get to cycle through all of the saved workbooks, open them individually, update the module and then close the workbook moving onto the next one.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Macro to edit macro

    If VBA project is protected... it's going to be difficult to say the least.

    I don't have time to go into all the details right now, but have a read of link below for how to use code to unlock protected project.
    https://stackoverflow.com/questions/...76557#16176557

    See below for sample code for inserting code into module (Module1). Note that reference to 'Microsoft Visual Basic For Applications Extensibility 5.3' is added.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-30-2019
    Location
    Cardiff, Wales
    MS-Off Ver
    Office 2016
    Posts
    10
    No problem. Will look into it and let you know how I got in. Thanks for your help.

  6. #6
    Registered User
    Join Date
    06-30-2019
    Location
    Cardiff, Wales
    MS-Off Ver
    Office 2016
    Posts
    10

    Re: Macro to edit macro

    Thanks for your help with this. Have looked into it a bit further and seems super complicated to be able to unlock the editor, let alone replace current modules. Will have a think of alternative options.

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Macro to edit macro

    You are welcome and good luck.

+ 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] New to VBA - how to edit and save buggy Macro without *running* the buggy macro
    By bsabiston in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2019, 05:56 PM
  2. Macro error 438--How to edit macro, so can cover more rows
    By ronlau123 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-12-2017, 11:09 PM
  3. Edit edit links macro to automate sheet selection
    By sds1126 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2015, 12:27 PM
  4. Replies: 2
    Last Post: 11-03-2014, 12:06 PM
  5. Macro Edit
    By Khaldon in forum Excel General
    Replies: 5
    Last Post: 04-21-2011, 05:22 PM
  6. Macro to open a program, edit a macro and run it
    By massimoo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-22-2010, 09:33 AM
  7. Using a Macro to edit a Macro (does that make sense?)
    By Kaisies in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2005, 02:00 PM

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