views:

35

answers:

2

I have a really annoying problem.

I am openign a word document via c# / COM Interop (Word 2007). I want to prevent the Macros from Running as some of them may crash (older files with missing bookmarks etc.).

So I run the following code to suppress all the dialogs that may pop up:

Word.ApplicationClass wordApplication = new Word.ApplicationClass();

wordApplication.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;

wordApplication.ShowVisualBasicEditor = false;

wordApplication.AutomationSecurity = 
  Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;

Word.Document wordDoc = null;

When I then execute the following code, I get the message box "Macros in this Project are Disabled".

 wordDoc = wordApplication.Documents.Open(
                ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing);

I need to either suppress this message, dettect if it is being shown and "ok" it or find a way of disableing startup macros without VB getting in the way.

Any Ideas?

A: 

This article might help. I'm not sure how you'd translate it to C#.

VBA code:

WordBasic.DisableAutoMacros 1   ' Disables auto macros
WordBasic.DisableAutoMacros 0   ' Enables auto macros

I don't know if this will disable the "Macros in this Project are Disabled" message.

Foole
A: 

I never could get this to work with C#, but with VB.NET it was fine. Here's how to do it: http://stackoverflow.com/questions/2846407/how-to-open-document-that-contains-autoopen-macro-with-powershell/3206081#3206081

Otaku