Print master/subdocuments via automation

Hi guru's,

I have the following problem:
I'm printing word documents via automation (c#), It works fine for normal
documents but when I try to print a master document with subdocuments it
doesn't print the collection of subdocuments, only references to it.
If I try to print them from the Word GUI I get a prompt asking me if I
want to open the subdocuments or not, so I guess that's where the problem
is, via automation it won't prompt me, so it doesn't open the subdocuments.

Is there a way to have word print the subdocuments?

PS: this is the method I use to print the word doc :
void PrintDOC(string FileName)
{
 Microsoft.Office.Interop.Word.ApplicationClass objApp = null;
 object objMissing = System.Reflection.Missing.Value;
 object objFalse = false;
 object objTarget = Microsoft.Office.Interop.Word.WdMergeTarget.wdMergeTargetSelected;
 object objUseFormatFrom = Microsoft.Office.Interop.Word.WdUseFormattingFrom.wdFormattingFromSelected;
 try
 {
  objApp = new Microsoft.Office.Interop.Word.ApplicationClass();
  object objDocName = FileName;
  objApp.ActivePrinter = cmbPrinter.SelectedItem.ToString();
  Microsoft.Office.Interop.Word.Document objDoc = null;
                  
  object oFalse = false;
  object oTrue = true;
  objDoc = objApp.Documents.Open(
   ref objDocName,    //FileName
   ref oFalse,   //ConfirmVersions
   ref oTrue,   //ReadOnly
   ref oFalse,   //AddToRecentFiles
   ref objMissing,   //PasswordDocument
   ref objMissing,   //PasswordTemplate
   ref objMissing,   //Revert
   ref objMissing,   //WritePasswordDocument
   ref objMissing,   //WritePasswordTemplate
   ref objMissing,   //Format
   ref objMissing,   //Enconding
   ref objMissing,   //Visible
   ref objMissing,   //OpenAndRepair
   ref objMissing,   //DocumentDirection
   ref objMissing   //NoEncodingDialog
  );
  object numcopies = (object)1;
  objDoc.PrintOut(
   ref oFalse,                  //Background
   ref oFalse,                  //Append
   ref objMissing,            //Range
   ref objMissing,            //OutputFileName
   ref objMissing,            //From
   ref objMissing,            //To
   ref objMissing,            //Item
   ref numcopies,            //Copies
   ref objMissing,            //Pages
   ref objMissing,            //PageType
   ref objMissing,            //PrintToFile
   ref objMissing,            //Collage
   ref objMissing,            //ActivePrinterMacGX
   ref objMissing,            //ManualDuplexPrint
   ref objMissing,            //PrintZoomColum
   ref objMissing,            //PrintZoomRow
   ref objMissing,            //PrintZoomPaperWidth
   ref objMissing            //PrintZoomPaperHeight
  );
  objApp.ActivePrinter = oriDefaultPrinter;
  objDoc.Close(ref oFalse,ref objMissing,ref objMissing);
  objDoc = null;
  objApp.Quit(ref oFalse,ref objMissing,ref objMissing);
  objApp = null;
 }
 catch(Exception e)
 {
  this.ShowError("Word document afprinten mislukt\nDe fout was:\n\n" + e.ToString());
 }
}
LVL 8
tomvergoteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PeppyCommented:
I think in VBA you have to expand the subdocuments within the master documents using ActiveDocument.Subdocuments.Open

Here is the full information

The Document Object Model
There isn’t a whole lot hidden behind the façade in this case, that can be revealed by diving into the VBE. The first two most obvious settings of interest to the VBA programmer, are ActiveDocument.IsMasterDocument and ActiveDocument.IsSubdocument. Both of these are Boolean values. The IsSubdocument value only indicates that the document was created with the Create Sub-document method or button. It does not mean that the document belongs to a Master document as a Sub.
The Subs themselves are referenced through the ActiveDocument.Subdocuments collection. This has several properties.
·      HasFile (Boolean) indicates that the Sub has been saved as a file. Of interest only when using the not recommended tools.
·      Level (Long) indicates the heading level used to create the Sub. If the Sub wasn’t created with the Master document toolset, which is the case if you are following this document, the number is set to 1 and is meaningless.
·      Locked (Boolean) indicates whether the Sub is locked for edit or not.
·      Name (String) is the Subs file name.
·      Path (String) is the Subs path.
·      Range (Range) is the range (a pair of numbers – the start and end points) in the document that the Sub covers.
There are three methods for a Sub - Open, Delete and Split that perform as per the façade’s toolset. Note that Delete does not delete the disk file nor remove the contents of the Sub; it just removes the Sub’s boundaries and existence in the Master.


Sorry I do not know C# but maybe this will be of some help to you to know.
0
Joanne M. OrzechManager, Document Services CenterCommented:
Tom:

Maybe I'm not understanding your question, and I don't know C# but do know some VBA.  That may be the way to go.  Are you wedded to C#?
0
tomvergoteAuthor Commented:
well it's a problem with an existing app in c#, rewriting it would be too much work so yes for this project I'm pretty much tied to c#
anyway, I have access to the document object as well so I suppose your hints apply as well. I get the ismasterdocument on my doc object as well.
I'll try to get this to work when I'm at the customer again, but thank you for your input so far.
May I ask where you got that information or do you know some sites. I'm having trouble googling usefull stuff on this
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Joanne M. OrzechManager, Document Services CenterCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomvergoteAuthor Commented:
only responding now since it's come to a conclusion

convinced the customer with the articles link from jorzech, so i'm accepting his answer
0
Joanne M. OrzechManager, Document Services CenterCommented:
Thanks much tomvergote!  Glad I could be of some assistance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.