Visual Studio 2008 (2010)에서 매크로 동작 안할때 조치 방법


1. 현상

    - Visual Studio의 Windows를 업데이트 한 이후 Visual Studio의 매크로 기능이 동작을 안한다.


2. 원인

    - 2014년 2월 14일 이후에 나온 Windows 업데이트를 적용할 경우 매크로가 작동하지 않는다.

    - 참고 자료 : Visual Studio 2010 Macros Stop Working after February 2014 Windows Update


3. 해결 방법

    1. Visual Studio 2008 혹은 2010을 종료한다.


    2. 다음 3개의 파일을 편집하여 하기 XML 데이터 내용을 추가한다.

        VS2008의 경우 아래와 같다.

 

"C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\9.0\VsaEnv\vsmsvr.exe.config"

"C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\9.0\VsaEnv\vsaenv.exe.config"

"C:\Program Files (x86)\Microsoft Visual Studio9.0\Common7\IDE\devenv.exe.config"




        VS2010의 경우 아래와 같다.

 

"C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\9.0\VsaEnv\vsmsvr10.exe.config"

"C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\9.0\VsaEnv\vsaenv10.exe.config"

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config"



    3. 상기 파일을 편집하여 다음 내용 추가

<configuration>

... <runtime> ... <AllowDComReflection enabled="true"/> ... </runtime> ... </configuration>




   3. 개발툴을 재 실행한다.




참고자료 : http://visualstudioextensions.vlasovstudio.com/2014/02/13/visual-studio-2010-macros-stop-working-after-february-2014-windows-update/




출처 : http://blog.naver.com/techshare/220138680455


Visual Studio 2013에서 가장 아쉬운 부분이 바로 매크로인데요. 다행히 "Visual Commander" 확장 도구를 이용하면 그와 같은 제약에서 벗어날 수는 있습니다.

Visual Commander
; http://vlasovstudio.com/visual-commander/


현재 Free, Professional 제품으로 나누어서 판매하고 있습니다.

Free 버전 다운로드 (Visual Commander v1.5 - December 23, 2013)
; http://vlasovstudio.com/visual-commander/VisualCommander_15.vsix

Professional Edition 구매 ($39)
; http://vlasovstudio.com/visual-commander/professional_edition.html


사용법도 간단합니다. vsix 설치 후 Visual Studio를 실행하면 "VCMD" 메뉴가 생기는데 거기서 "Commands"를 선택한 후 "Add" 버튼을 누르면 다음과 같이 기본 매크로 함수를 위한 뼈대가 생성됩니다.




예를 들어, 제가 Visual Studio 2010에서 사용했던 매크로 함수는 다음과 같은데요.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE100
Imports System.Diagnostics

Public Module InsertTag

    Sub InsertCenterHr()
        Dim selection As TextSelection

        If (ActiveDocument() Is Nothing) Then
            Exit Sub
        End If

        selection = DTE.ActiveDocument.Selection()

        Dim str As String
        str = "<hr style='width: 50%' />" & Environment.NewLine
        SetText(selection, str)
    End Sub

    Sub SetText(ByVal selection As TextSelection, ByVal txt As String)
        Dim prop As EnvDTE.Property
        prop = DTE.Properties("TextEditor", "PlainText").Item("IndentStyle")
        Dim previousIndent = prop.Value
        prop.Value = 0

        selection.Text = txt

        prop.Value = previousIndent

    End Sub

End Module


이를 Visual Commander에서는 다음과 같이 동일하게 코드를 복사해서 사용할 수 있습니다.

Imports EnvDTE
Imports EnvDTE80
Imports System

Public Class C
    Implements VisualCommanderExt.ICommand

    Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run

            Dim selection As TextSelection
            Dim activeDocument As EnvDTE.Document

            activeDocument = DTE.ActiveDocument

            If (activeDocument Is Nothing) Then
                    Exit Sub
            End If

            selection = activeDocument.Selection()

            Dim str As String
            str = "<hr style='width: 50%' />" & Environment.NewLine
            SetText(DTE, selection, str)        
    End Sub


        Sub SetText(DTE As EnvDTE80.DTE2, ByVal selection As TextSelection, ByVal txt As String)
            Dim prop As EnvDTE.Property
            prop = DTE.Properties("TextEditor", "PlainText").Item("IndentStyle")
            Dim previousIndent = prop.Value
            prop.Value = 0

            selection.Text = txt

            prop.Value = previousIndent

        End Sub
End Class


보시는 바와 같이 DTE 변수를 넘겨준다는 점을 제외하고는 거의 차이가 없습니다.

불편한 점은 사용법에 있습니다. 이전에는 매크로 탐색기에서 해당 매크로를 더블-클릭하면 실행이 가능했지만, "Visual Commander"의 경우 "Commands" 창에서 더블-클릭해 실행하는 것을 지원하지 않고 있습니다. 매번 "VCMD" 메뉴를 펼쳐서 새롭게 등록된 명령어를 선택해 줘야 하는데요. 물론 이 부분은 기본적으로 단축키 등록을 통해 우회적으로 해결할 수는 있지만 어쨌든 불편한 것은 사실입니다. 
(이 부분을 제가 요청했는데 최신 버전에서 개발자가 그 의견을 받아들여 수정했습니다. 이제 예전의 Macro Explorer처럼 편리하게 사용할 수 있습니다.) 

매크로가 그리웠던 분들... ^^ 지금 설치해 보세요.




참고로 아래 코드는 현재 제가 사용하고 있는 _T("") 자동으로 해 주는 매크로 소스입니다.

Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic

Public Class C
	Implements VisualCommanderExt.ICommand

	Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run

		'DESCRIPTION: This macro will automatically put "_T( )" around 
		'             your strings, Author: Orin Walker, 1999, Version 1.1
		'             Last change - Acidpop(http://acidpop.tistory.com) (2012.09.07)
		'             Supported Visual Studio 2010 Macro
		Dim iCount As Integer
		Dim bFoundAQuote As Boolean
		Dim strTemp As String
		Dim strStuffAtEnd As String
		Dim bDone As Boolean
		Dim str As String
		Dim strBuildString As String
		Dim Selection As TextSelection
		Dim win as Window

		win = DTE.ActiveWindow
		If (win.type <> EnvDTE.vsWindowType.vsWindowTypeDocument) And (win.type <> EnvDTE.vsWindowType.vsWindowTypeCodeWindow) Then
'			MsgBox( "type=" & win.type & "  Doc=" & EnvDTE.vsWindowType.vsWindowTypeDocument & "  CodeWin=" &  EnvDTE.vsWindowType.vsWindowTypeCodeWindow )
			Exit Sub
		End If

		iCount = 0
		bFoundAQuote = False
		DTE.ActiveDocument.Selection.SelectLine()
		strTemp = DTE.ActiveDocument.Selection.Text

		Selection = DTE.ActiveDocument.Selection

		strStuffAtEnd = ""
		While bDone <> True
			str = ParseString(strTemp, bFoundAQuote, strStuffAtEnd)
			strBuildString = strBuildString + str

			If bFoundAQuote = True Then
				strTemp = strStuffAtEnd
			Else
				bDone = True
				'DTE.ActiveDocument.Selection.Delete()
				'DTE.ActiveDocument.Selection = strBuildString
				Selection.Text = strBuildString
			End If
			iCount = iCount + 1
			If iCount > 100 Then    ' safety valve
				bDone = True
			End If
		End While
		'End If
	End Sub
    Function ParseString(ByVal strTemp, ByRef bFoundAQuote, _
                         ByRef strStuffAtEnd)
		Dim strSpace As String
		Dim iLen As Integer
		Dim iPos As Integer
		Dim x As Integer
		Dim strCheck As String
		Dim iUnderscoreTPos As Integer
		Dim strBeforeFirstQuote As String
		Dim strNewTempStr As String
		Dim strRemaining As String
		Dim strStuffInQuotes As String


		'DESCRIPTION: This is a helper function for the UnderscoreT macro,
		'             Author: Orin Walker, 1999, Version 1.1
		' Comment in/out whatever style you prefer       
		strSpace = ""   ' NO space before or after "_T("
		'strSpace = " " ' Add a space before and after "_T("
		iLen = Len(strTemp)
		bFoundAQuote = False
		' Get the position of the first quote on the line
		iPos = InStr(strTemp, Chr(34))
		If iPos > 0 Then    'a quote was found
			' Go back and see if we have an existing 
			' _T( defined for this quote
			x = iPos - 5          ' Go back up to 5 characters
			If x <= 0 Then      ' If we have reached the 
				' beginning of our string
				x = 1           ' Set x to start at the first character
			End If
			strCheck = Mid(strTemp, x, iPos)

			iUnderscoreTPos = InStr(strCheck, "_T(")

			' If we found one grab everything before the first quote
			strBeforeFirstQuote = Mid(strTemp, 1, iPos - 1)
			If iUnderscoreTPos > 0 Then     ' we found an "_T("
				' Do NOT add the "_T(" to our temporary string
				strNewTempStr = strBeforeFirstQuote
			Else
				' Now create our new temporary string and append "_T("
				strNewTempStr = strBeforeFirstQuote + "_T(" + strSpace
			End If
			' Get the remaining string
			strRemaining = Mid(strTemp, iPos + 1, iLen)

			iLen = Len(strRemaining)
			' Now find the second quote
			iPos = InStr(strRemaining, Chr(34))

			If iPos > 0 Then
				' If we found one save the stuff in quotes
				strStuffInQuotes = Chr(34) + Mid(strRemaining, 1, iPos)

				' And grab the stuff after the quotes
				strStuffAtEnd = Mid(strRemaining, iPos + 1, iLen)

				If iUnderscoreTPos > 0 Then     ' we found an _T(
					' Do NOT add the final ")" to our parsed string, 
					' because it alreasy exists
					ParseString = strNewTempStr + strStuffInQuotes
				Else
					' Create our parsed string
					ParseString = strNewTempStr + strStuffInQuotes + _
						strSpace + ")"
				End If
				bFoundAQuote = True
			Else
				' No SECOND quote was found so just return 
				' what was passed in
				ParseString = strTemp
			End If
		Else
			' No quote was found so just return what was passed in
			ParseString = strTemp
		End If
    End Function
End Class

 

 

 

 

다음은 CPP 파일과 .H 파일을 서로 왔다 갔다 해 주는 소스입니다.

Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic
 
Public Class C
    Implements VisualCommanderExt.ICommand
 
    Function GetFilenameFromPath(ByVal strPath As String) As String
        ' Returns the rightmost characters of a string upto but not including the rightmost '\'
        ' e.g. 'c:\winnt\win.ini' returns 'win.ini'

        If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
            GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
        End If
    End Function

    Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
        '////////////////////////////////////////////
        'Nooruddin Kapasi 1998.
        'Pavel Sokolov , CEZEO software , http://www.cezeo.com , Adaptation for .NET
        'DESCRIPTION: Switch Between Header and cpp
        '////////////////////////////////////////////

        Dim a As String
        Dim b As String
        Dim Flag As Integer
        Dim tmp As String
        Flag = 0
        a = DTE.ActiveDocument.FullName()
        tmp = InStr(a, ".cpp")
        If tmp Then
            b = Left(a, Len(a) - 3) + "h"
            Flag = 1
        Else
            tmp = InStr(a, ".h")
            If tmp Then
                b = Left(a, Len(a) - 1) + "cpp"
                Flag = 1
            End If
        End If

        If Flag Then
            Try
                DTE.Documents.Open(b, "Text")
            Catch
                a = GetFilenameFromPath(DTE.ActiveDocument.FullName())
                tmp = InStr(a, ".cpp")
                If tmp Then
                    b = Left(a, Len(a) - 3) + "h"
                    Flag = 1
                Else
                    tmp = InStr(a, ".h")
                    If tmp Then
                        b = Left(a, Len(a) - 1) + "cpp"
                        Flag = 1
                    End If
                End If

                a = DTE.Solution.FindProjectItem(b).FileNames(0)
                DTE.Documents.Open(a, "Text")

            End Try

        End If
    End Sub
End Class
 

 

 


다음은 선택 영역을 //로 주석 처리 해 주는 소스입니다.
Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic

Public Class C
	Implements VisualCommanderExt.ICommand

	Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
            Dim win
            win = DTE.ActiveWindow
 
	    If (win.type <> EnvDTE.vsWindowType.vsWindowTypeDocument) And (win.type <> EnvDTE.vsWindowType.vsWindowTypeCodeWindow) Then
           	  MsgBox( "This macro can only be run when a text editor window is active." )
		  Exit Sub
            else
                if InStr( DTE.ActiveDocument.Selection.Text, vbCr ) > 0 then
                    DTE.ActiveDocument.Selection.ReplaceText( "^", "//", EnvDTE.DsTextSearchOptions.dsMatchRegExp )
                End If
            End If
	End Sub

End Class

 

 

 

 

다음은 선택 영역의 //로 된 주석을 해제 해 주는 소스입니다.

Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic

Public Class C
	Implements VisualCommanderExt.ICommand

	Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
		Dim win
		win = DTE.ActiveWindow
	       If (win.type <> EnvDTE.vsWindowType.vsWindowTypeDocument) And (win.type <> EnvDTE.vsWindowType.vsWindowTypeCodeWindow) Then
           	       MsgBox( "This macro can only be run when a text editor window is active." )
		       Exit Sub
              else
			DTE.ActiveDocument.Selection.ReplaceText( "^//", "", EnvDTE.DsTextSearchOptions.dsMatchRegExp )
		End If
		
	End Sub

End Class



출처 : http://blog.naver.com/techshare/220138680455


액셀에서 매크로는 아주 편리한 기능을 합니다.

거기다 VB 언어로 되어있어 프로그래밍도 가능하죠.

매크로로 2개의 셀을 자동으로 병합해 주는 기능을 만들어볼까 합니다.


아래 그림과 같이 셀이 준비 되어있다고 할때,

기존에는 2개의 셀을 선택한 다음에 마우스 클릭으로 병합을 일일이 해 줘야 하는데요

한, 두개면 상관 없지만 이게 몇 십개 몇 백개라면 문제가 됩니다. 시간이 오래걸리죠.

이 작업을 매크로로 하게 되면 쉽게 처리할 수 있습니다.



우선 매크로를 기록해야 합니다.

보기 탭의 매크로를 눌러보면 메뉴가 나오는데 거기서 매크로 기록을 누르세요.



병합 작업을 쉽게 하기 위해서는 단축키가 필수인데요.

단축키는 알아서 편리한 단축키로 설정하세요.

저는 CTRL+Q로 지정하였습니다.



단축키 지정이 끝나고 확인을 눌렀으면 이제 그냥 매크로 기록 중지하세요.

매크로 내용은 직접 넣을테니까요.



매크로 기록이 중지 되었으니 이제 편집을 해야죠.

편집하기 전에 매크로 보기를 해야 합니다.



매크로 목록이 나오면 "편집" 버튼을 누릅니다.




매크로를 편집할 수 있는 비쥬얼베이직 창이 실행되는데요...

여기다가 아래 코드를 넣으면 끝입니다. 소스는 아래에 있으니 복사해서 붙여넣기 하세요.




소스를 모두 붙여 넣었으면 이제 테스트 해봐야겠죠.

A의 1번 셀을 선택하고 단축키(저는 CTRL+Q)를 눌러봅니다.

아주 잘 실행되서 병합이 한방에 되었습니다.

B번 셀도 해보고, C번 셀도 해봤습니다.

모두 병합되었네요.




아래의 소스코드를 적당하게 복사해서 비쥬얼 베이직프로그램 창(매크로 편집 창)에 붙여넣으세요.


Sub 매크로1()
'
' 매크로1 매크로
'
' 바로 가기 키: Ctrl+q
'
    
    On Error Resume Next
    
    CurRow = ActiveCell.Row
    CurCol = ActiveCell.Column
    
    ' 병합할 셀의 내용을 지워야 확인창이 안뜬다.
    ' 한 셀의 내용이 지워진다라는 내용의 확인창.
    Cells(CurRow + 1, CurCol).Value = ""
    
    ' 현재 셀과 다음 셀을 선택한다.
    Range(Cells(CurRow, CurCol), Cells(CurRow + 1, CurCol)).Select
    
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Merge
    
End Sub


+ Recent posts