Question

I am trying to automate a find/replace task in Visual Studio. I used the macro recorder and got the code below. When the macro is run, it doesn't seem to have any effect. (I tried both with Quick Replace and Replace in Files without success). I have no clue what is wrong. Can anyone help ?

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module RecordingModule

    Sub CommaSpace()
        DTE.Find.Target = vsFindTarget.vsFindTargetFiles
        DTE.Find.MatchWholeWord = False
        DTE.Find.Action = vsFindAction.vsFindActionFindAll
        DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Activate() 'Find and Replace
        DTE.Find.MatchCase = False
        DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
        DTE.Windows.Item("Eigen3x3.cpp").Activate()
        DTE.Find.FindWhat = ","
        DTE.Find.ReplaceWith = ", "
        DTE.Find.Target = vsFindTarget.vsFindTargetFiles
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.MatchInHiddenText = True
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
        DTE.Find.SearchPath = "Entire Solution"
        DTE.Find.SearchSubfolders = True
        DTE.Find.KeepModifiedDocumentsOpen = False
        DTE.Find.FilesOfType = ""
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResults1
        DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
        If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
            Throw New System.Exception("vsFindResultNotFound")
        End If
    End Sub
End Module
Was it helpful?

Solution

First of all check that your macros still work and not disabled after the February Windows Update: Visual Studio Macros stopped working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top