Log in

View Full Version : Solved: Word 2007 - Error expanding subdocuments in a master document



jfair3017
07-18-2007, 06:38 AM
Hi,

The following code in C# that used to work in office 2003 does not work anymore in office 2007. I'm trying to expand the subdocuments within a master document (oDoc). The error I receive is 'Unspecified error'.

if (oDoc.Subdocuments.Count >= 1)
{
oDoc.Subdocuments.Expanded = true;
}

I noticed when opening up the master document in Word 2007 that there is an extra step required to expand subdocuments.

From the outline view,
1) Click Show Document
2) Click Expand Sub Documents

The code works fine if the master document is saved after the show document button has been clicked. But, I'd like be to able to simulate the clicking of the Show document button programmatically.

Any ideas are appreciated.

Thanks,

John

daniel_d_n_r
07-24-2007, 03:20 PM
Sorry I am not very informed on C#.
But have you tried recompiling the code in Visual Studio?
It often has to update code when recompiling older versions.

jfair3017
07-25-2007, 05:35 AM
The problem is not isolated to Visual Studio.

I was able to replicate the problem in VBA by creating a Macro within Word 2007. This is the only line in my macro:

ActiveDocument.Subdocuments.Expanded=true

There is an 'Outlining tab' in Word 2007. If you don't have the 'Show Document' button clicked and you run the macro. You receive an 'Unspecified Error' message. The macro runs fine if the Show Document button has been clicked. I'd like to replicate the clicking of the Show Document button programatically.

jfair3017
09-11-2007, 07:48 AM
Solved.. here's the C# code:

public void expandSubdocuments(Word._Document oDoc)
{
oWord.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdOutlineView;

if (oDoc.Subdocuments.Count >= 1)
{
if (!oDoc.CommandBars["Outlining"].Controls["&Create Subdocument"].Visible)
{
oDoc.CommandBars["Outlining"].Controls["&Master Document View"].Execute();
}
oDoc.Subdocuments.Expanded = true;
}
}