Re: Possible to do a search/replace in the IDE Code window with VBA?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Bernie,

You are an MVP hero! The comprehensiveness of your help is a solution and an applied teaching
moment.

EagleOne

"Bernie Deitrick" <deitbe @ consumer dot org> wrote:

The code below requires a reference to MS VBA Extensibility (whichever version you have). This
does a global replace, so be careful that you are replacing a unique string...

HTH,
Bernie
MS Excel MVP

Sub ReplaceCodeInModule()
Dim myCode As String
Dim WhatToFind As String
Dim ReplaceWith As String
Dim modName As String
Dim myBook As Workbook

WhatToFind = "Hello"
ReplaceWith = "Hello World"
modName = "Module1"

Set myBook = ActiveWorkbook

With myBook.VBProject.VBComponents.Item(modName).CodeModule
myCode = .Lines(1, .CountOfLines)
myCode = Replace(myCode, WhatToFind, ReplaceWith)
.DeleteLines 1, .CountOfLines
.InsertLines .CountOfLines + 1, myCode
End With

End Sub

<EagleOne@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:fs6q2558ihgcovjk982ve4vte58crr4fle@xxxxxxxxxx
2003/ 2007

Is it possible, using VBA, to do a search/replace in another VBA module's IDE Code window with
VBA?

If so, What objects are involved? Is there a link explaining the process?

TIA EagleOne


.



Relevant Pages

  • Re: Using VBA to replace text
    ... > Dim FindWhat As String ... > Dim ReplaceWith As String ... > FindWhat = "EDS is a registered mark and the EDS logo is a trademark ...
    (microsoft.public.powerpoint)
  • Re: Using VBA to replace text
    ... Dim FindWhat As String ... Dim ReplaceWith As String ... FindWhat = "EDS is a registered mark and the EDS logo is a trademark ...
    (microsoft.public.powerpoint)
  • Re: Possible issue with Shyam Pillais GlobalFindAndReplace?
    ... Dim oPres As Presentation ... Dim ReplaceWith As String ... Dim Sldnum As Long, Shpnum As Long ...
    (microsoft.public.powerpoint)
  • RE: Odd VBA Replace behavior in PPT2007
    ... Dim oPres As Presentation ... Dim ReplaceWith As String ... Dim oTmpRng As TextRange ...
    (microsoft.public.powerpoint)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)