?
Solved

Print master/subdocuments via automation

Posted on 2005-03-03
6
Medium Priority
?
493 Views
Last Modified: 2008-01-09
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());
 }
}
0
Comment
Question by:tomvergote
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:Peppy
ID: 13449632
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
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 13451393
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
 
LVL 8

Author Comment

by:tomvergote
ID: 13451625
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 37

Accepted Solution

by:
Joanne M. Orzech earned 1000 total points
ID: 13451890
0
 
LVL 8

Author Comment

by:tomvergote
ID: 13624025
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
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 13630634
Thanks much tomvergote!  Glad I could be of some assistance.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question