Search code examples
c#ms-wordoffice-interop

Word document Page Setup takes forever


the following 2 code lines cause my program to somehow not continue the rest of the methods code:

Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
WordApp.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
document = WordApp.Documents.Add();
document.PageSetup.TopMargin = 5;
document.PageSetup.Orientation = WdOrientation.wdOrientLandscape;

The application does not freeze. Every single breakpoint after these lines will never be reached.

If I take these lines out, the rest of the code runs through and works fine.


Solution

  • Resolved: The problems cause was the network printer. Because word needs a connection to a printer to set Page setup and it couldn't establish the connection to the printer, it waited. Setting the default printer to another one solved the issue.