+ Reply to Thread
Results 1 to 4 of 4

Search for a line in all Modules in a workbook and add extra line below

  1. #1
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Search for a line in all Modules in a workbook and add extra line below

    Hello,

    I would like to search for a line of code in all modules in a workbook and add additional code below it. For example, search for:

    wb1.Close SaveChanges:=False

    and below it add

    wb2.Close SaveChanges:=False
    wb3.Close SaveChanges:=True


    I searched at the cpearson website but had no success editing any of the examples provided. Can vba be used to edit modules as I described above or is a workaround necessary?

    Thank you

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search for a line in all Modules in a workbook and add extra line below

    Hello sans,

    Which modules are you referring to? The ones modules in the VBIDE?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Re: Search for a line in all Modules in a workbook and add extra line below

    Hi Leith,

    Yes, I'm referring to the modules in the Visual Basic Editor. I have more than around 120 modules which I need to edit in several workbooks. It would be very time consuming to edit them manually hence my original question.

    Thank you for the reply.

  4. #4
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Re: Search for a line in all Modules in a workbook and add extra line below

    Hello,
    If anyone knows how to do this with vba it would save me a lot of time. I don't know if it's easier but a search and replace would also work,

    i.e. search for

    wb1.Close SaveChanges:=False

    and replace it with

    wb1.Close SaveChanges:=False
    wb2.Close SaveChanges:=False
    wb3.Close SaveChanges:=True


    Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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