방법: 숨김 모드에서 Word 대화 상자 사용

업데이트: 2007년 11월

적용 대상

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

프로젝트 형식

  • 문서 수준 프로젝트

  • 응용 프로그램 수준 프로젝트

Microsoft Office 버전

  • Word 2003

  • Word 2007

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

Microsoft Office Word에서 기본 제공 대화 상자를 사용자에게 표시하지 않고 호출하여 메서드 호출 한 번으로 복잡한 작업을 수행할 수 있습니다. Dialog 개체의 Display 메서드를 호출하지 않고 Execute 메서드를 사용하여 이 작업을 수행할 수 있습니다.

예제

Friend Sub PageSetupDialogHidden()
    Dim dlg As Word.Dialog = Application.Dialogs.Item(Word.WdWordDialog.wdDialogFilePageSetup)

    ' Set the properties of the dialog box.
    ' ControlChars.Quote() is used to represent the symbol for inches.
    With dlg
        .PageWidth = 3.3 & ControlChars.Quote
        .PageHeight = 6 & ControlChars.Quote
        .TopMargin = 0.71 & ControlChars.Quote
        .BottomMargin = 0.81 & ControlChars.Quote
        .LeftMargin = 0.66 & ControlChars.Quote
        .RightMargin = 0.66 & ControlChars.Quote
        .HeaderDistance = 0.28 & ControlChars.Quote
        .Orientation = Word.WdOrientation.wdOrientPortrait
        .DifferentFirstPage = False
        .FirstPage = 0
        .OtherPages = 0

        ' Apply these settings only to the current selection with this line of code:
        .ApplyPropsTo = 3

        ' Apply the settings.
        .Execute()
    End With
End Sub
private void PageSetupDialogHidden() 
{ 
    Word.Dialog dlg = Application.Dialogs[Word.WdWordDialog.wdDialogFilePageSetup];

    invokeHelper(dlg,"PageWidth","3.3\"");
    invokeHelper(dlg,"PageHeight","6\"");
    invokeHelper(dlg,"TopMargin","0.71\"");
    invokeHelper(dlg,"BottomMargin","0.81\"");
    invokeHelper(dlg,"LeftMargin","0.66\"");
    invokeHelper(dlg,"RightMargin","0.66\"");
    invokeHelper(dlg,"HeaderDistance","0.28\"");
    invokeHelper(dlg,"Orientation","0");
    invokeHelper(dlg,"DifferentFirstPage","0");
    invokeHelper(dlg,"FirstPage","0");
    invokeHelper(dlg,"OtherPages","0");

    // Apply these settings only to the current selection with this line of code:
    invokeHelper(dlg,"ApplyPropsTo","3"); 

    // Apply the settings.
    dlg.Execute(); 
}

private static void invokeHelper(Word.Dialog dlg, string member, string value)
{
    System.Type dlgType = typeof(Word.Dialog);

    // Set the appropriate property of the dialog box.
    dlgType.InvokeMember(member,
        System.Reflection.BindingFlags.SetProperty |
            System.Reflection.BindingFlags.Public |
            System.Reflection.BindingFlags.Instance,
        null, dlg, new object[] {value},
        System.Globalization.CultureInfo.InvariantCulture);
}

코드 컴파일

Visual Studio Tools for Office 프로젝트의 ThisDocument 또는 ThisAddIn 클래스에서 이 코드를 실행하십시오.

이 예제에서는 사용자 입력을 전혀 사용하지 않은 채 wdDialogFilePageSetup 열거형을 사용하여 여러 페이지 설정 속성을 지정합니다. 이 코드에서는 Dialog 개체를 사용하여 사용자 지정 페이지 크기를 구성합니다.

이 예제를 사용하려면 Visual Basic 코드에서 Option Strict Off를 설정해야 합니다. 위쪽 여백, 아래쪽 여백 등과 같은 페이지 설정을 위한 특정 설정은 Dialog 클래스의 멤버가 아니기 때문입니다. 이러한 설정은 런타임에 wdDialogFilePageSetup 열거형을 처리할 때 Word에서 동적으로 만들어지므로 런타임에 바인딩되는 속성입니다. 실제로 이들 속성은 각각의 개별 대화 상자의 컨트롤에 일치하도록 런타임에 작성됩니다.

참고:

Option Strict Off로 실행해야 할 코드를 별도의 클래스에 구분할 수 있습니다.

참고 항목

작업

방법: Word의 기본 제공 대화 상자 사용

개념

Word 개체 모델 개요