SHARE
Facebook X Pinterest WhatsApp

Global find and replace macro

I have noticed someone wanting a global find and replace for Visual c++ developer studio 97. I needed that to so I made a couple of VBSCRIPT macros to do it. They are quite simple and possibly even somewhat crude but they do the job quite well. Maybe somebody has done this sort of thing […]

Written By
thumbnail
CodeGuru Staff
CodeGuru Staff
Jan 26, 1999
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

I have noticed someone wanting a global find and replace for Visual c++ developer
studio 97. I needed that to so I made a couple of VBSCRIPT macros to do it. They are
quite simple and possibly even somewhat crude but they do the job quite well. Maybe
somebody has done this sort of thing before but here they are for what its worth.

To use the macros do the following:

  • open a document or documents
  • mark the text to replace ( usual stuff, pressing SHIFT or using mouse )
  • run the macro ( FindAndReplace for single file, GlobalFindAndReplace for global ).

Remarks:

  • In case no text is selected (marked) nothing happens.
  • “Global” find and replace is liimted to all open files (but Developer studio can really keep open a lot of them at the same time)

VBSCRIPT MACROS:

Sub GlobalFindAndReplace()
    ‘DESCRIPTION: Does a global find and replace in all open documents.
    ‘Small, quick macro, but it can be useful.
    MatchCase=4
    FindText=ActiveDocument.Selection
    if len(FindText) <> 0 then
        ReplaceText=InputBox(“Replace all occurrences of text: “+ vbCrLf + ” => ” + Findtext + vbCrLf +”with text :”)
        if len(ReplaceText) <>0 then
            for each doc in Application.Documents
                while Doc.Selection.FindText(FindText,MatchCase)
                    Doc.Selection=ReplaceText
                wend
            next
        end if
    end if
End Sub
Sub FindAndReplace()
    ‘DESCRIPTION: Does a find and replace in the currently displayed open document
    ‘Small, quick macro, but it can be useful.
    MatchCase=4
    FindText=ActiveDocument.Selection
    if len(FindText) <> 0 then
        ReplaceText=InputBox(“Replace all occurrences of text: “+ vbCrLf + ” => ” + Findtext + vbCrLf +”with text :”)
        if len(ReplaceText) <>0 then
            while ActiveDocument.Selection.FindText(FindText,MatchCase)
                ActiveDocument.Selection=ReplaceText
            wend
        end if
    end if
End Sub

Recommended for you...

Top Plugins for Visual Studio
Enrique Stone
Feb 3, 2023
Developer News Is Coming Back to Visual Studio
Hannes DuPreez
Jan 24, 2023
GitHub Copilot Overview
Hannes DuPreez
Aug 6, 2022
Visual Studio 2022 for Mac Released
Hannes DuPreez
Jun 20, 2022
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.