Problem printing labels

Posted on 2005-05-09
Last Modified: 2012-05-05
I have a C# WinForms app and am trying to print labels from it.  I need to
print a label each time a certain type of record is added, so I need to print
labels one at a time.  I set up a Word application and it worked fine for other
purposes, but when I added this code I get the error:

"method or property is not available because a document window is not active"

Here is the code:
bool SingleLabel = true;
object Name = "4013";
object Address = ClName.Text +"\r\nTest Company Name\tTest Rep";

oWord.Application.MailingLabel.DefaultPrintBarCode = false;

//First I tried this line

oWord.Application.MailingLabel.CreateNewDocument(ref Name,ref Address,ref missing,ref missing,ref missing);

//Then I tried this line

oWord.Application.MailingLabel.PrintOut(ref Name,ref Address,ref missing,ref missing,ref SingleLabel, ref missing,ref missing);

I saw similar code in numerous examples and do not know what is missing.  In one place there was a suggestion that it could be a MS bug and to be sure I had Office SP3, but I upgraded it only to get same results.  Word version is 9.0.6926 SP-3.

Any help is appreciated.  I did not think this would be difficult but now it is threatening my deadline!!!!!!!!!!!!!!!!!!!

Question by:zoseri

    Author Comment

    FIgured it out for myself - but thought I would post the answer in case anyone else runs into this problem....

    oWord.Application.Documents.Add(ref missing, ref missing,
          ref missing, ref missing);

    Have to add this before trying to print the label.  This has the effect of "new blank document".  I thought that CreateNewDocument would do this for me, but apparently not!

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now