방법: 문서에서 관리 코드 확장 제거(2007 시스템)

업데이트: 2007년 11월

적용 대상

이 항목의 정보는 지정된 Visual Studio Tools for Office 프로젝트 및 Microsoft Office 버전에만 적용됩니다.

프로젝트 형식

  • 문서 수준 프로젝트

Microsoft Office 버전

  • 2007 Microsoft Office system

자세한 내용은 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.

2007 Microsoft Office system용 문서 수준 사용자 지정의 일부인 문서 또는 통합 문서에서 Visual Studio Tools for Office 사용자 지정 어셈블리를 프로그래밍 방식으로 제거할 수 있습니다. 그런 다음 사용자가 문서를 열어 내용을 보면 문서에 추가한 사용자 지정 UI(사용자 인터페이스)가 표시되지 않고 코드가 실행되지 않습니다.

Visual Studio Tools for Office 런타임에서 제공되는 RemoveCustomization 메서드 중 하나를 사용하여 사용자 지정 어셈블리를 제거할 수 있습니다. 사용하는 메서드는 런타임에 Visual Studio Tools for Office 솔루션의 코드를 실행하여 사용자 지정을 제거할지, 아니면 닫혀 있는 문서나 Microsoft Office가 설치되지 않은 서버에 있는 문서에서 사용자 지정을 제거할지에 따라 달라집니다.

런타임에 사용자 지정 어셈블리를 제거하려면

닫혀 있는 문서 또는 서버에 있는 문서에서 사용자 지정 어셈블리를 제거하려면

  1. 콘솔 응용 프로그램이나 Windows Forms 프로젝트와 같이 Word 또는 Excel을 시작하지 않는 새 프로젝트를 만듭니다.

  2. 프로젝트에 Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll 어셈블리에 대한 참조를 추가합니다.

  3. 코드 파일의 맨 위에 다음 Imports 또는 using 문을 추가합니다.

    Imports Microsoft.VisualStudio.Tools.Applications
    
    using Microsoft.VisualStudio.Tools.Applications;
    
  4. ServerDocument 클래스의 정적 RemoveCustomization 메서드를 호출하고 매개 변수의 솔루션 문서 경로를 지정합니다.

    다음 코드 예제에서는 데스크톱에 있는 WordDocument1.docx라는 문서에서 사용자 지정을 제거한다고 가정합니다.

    Dim documentPath As String = System.Environment.GetFolderPath( _
        Environment.SpecialFolder.Desktop) & "\WordDocument1.docx"
    Dim runtimeVersion As Integer = 0
    
    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            ServerDocument.RemoveCustomization(documentPath)
            System.Windows.Forms.MessageBox.Show("The customization has been removed.")
        End If
    Catch ex As FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As IOException
        System.Windows.Forms.MessageBox.Show("The specified document is read-only.")
    Catch ex As InvalidOperationException
        System.Windows.Forms.MessageBox.Show("The customization could not be removed." & _
            vbLf & ex.Message)
    End Try
    
    string documentPath = System.Environment.GetFolderPath(
        Environment.SpecialFolder.Desktop) + @"\WordDocument1.docx";
    int runtimeVersion = 0;
    
    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
    
        if (runtimeVersion == 3)
        {
            ServerDocument.RemoveCustomization(documentPath);
            System.Windows.Forms.MessageBox.Show("The customization has been removed.");
        }
    }
    catch (FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (IOException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document is read-only.");
    }
    catch (InvalidOperationException ex)
    {
        System.Windows.Forms.MessageBox.Show("The customization could not be removed.\n" +
            ex.Message);
    }
    

참고 항목

작업

방법: ServerDocument 클래스의 두 버전을 모두 사용하는 코드 작성

방법: 문서에 관리 코드 확장 연결(2007 시스템)

방법: 문서에서 관리 코드 확장 제거(2003 시스템)

방법: 문서에 관리 코드 확장 연결(2003 시스템)

개념

ServerDocument 클래스를 사용하여 서버의 문서 관리