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);
}