Options

Word Automation: Print then Quit

Q1970Q1970 Member Posts: 34
Hi there. Looks like I need your help again.

I export data to Word and want to print my document on the system default printer, then close Word without saving anything.

The line

WordApp.PrintOut;

works perfectly for me, but when I try to close Word, by adding

WordApp.Quit(i); // (i = 0)

it closes like I ask it to, but it seems to kill the printjob as well. I tried...

WordApp.PrintOut;
COMMIT;
WordApp.Quit(i); // (i = 0)

But that doesn't work either. Ì tried to set my PDF printer as default printer too. The driver acknowledges my request, asks for a filename and starts making the file. But the resulting PDF-document is a currupted file (size: 0 bytes) that Adobe Reader can't read.

Once i remove the

WordApp.Quit(i); // (i = 0)

line, everything works fine again, apart from Word not closing.

Any suggestions?

Thanks in advance.

/Q

Comments

  • Options
    Rene70Rene70 Member Posts: 25
    Hi,

    here is a code-peace that works fine for me. Maybe it helps.


    CREATE(WordApp);

    WordApp.Visible := TRUE;

    WordDocs := WordApp.Documents;
    WordDoc := WordDocs.Open2002(Pfad);

    a := 3;
    WordDoc.Shapes.Item(a).Select;
    WordApp.Selection.TypeText(Vorname + ' ' + Nachname);

    a := 1;
    WordDoc.Shapes.Item(a).Select;
    WordApp.Selection.TypeText(FORMAT(Erstellungsdatum,0,'<Day,2>.<Month,2>.<Year4>'));

    a := 2;
    WordDoc.Shapes.Item(a).Select;
    WordApp.Selection.TypeText(BC.TextVerschlüsseln('$' + Nummer));

    a := 4;
    WordDoc.Shapes.Item(a).Select;
    WordApp.Selection.TypeText('Kartennr. ' + Kartennummer);

    WordApp.ActivePrinter(Druckername);

    WordDoc.PrintOut;
    WordDoc.Close;

    IF WordDocs.Count = 0 THEN
    WordApp.Quit;
  • Options
    ta5ta5 Member Posts: 1,164
    Hi
    Try to use a loop until background printing has finished
    REPEAT
      SLEEP(1000);
      iSleep := iSleep + 1;
    UNTIL (WordApp.BackgroundPrintingStatus = 0) OR (iSleep = 100);
    
  • Options
    ImIm Member Posts: 11
    tagging along...
    Do u know where I can get more info on the methods and properties of the word.. as automation server. F1 doesn't give any.

    eg Rene70 has ...Open2002(Pfad) what datatype is Pfad
    also the Select... how do I equate that to the word doc. Please point me to the right direction. Be very grateful

    Thank U ](*,)
  • Options
    ta5ta5 Member Posts: 1,164
    Excellent help on WordAutomation:
    VBAWRD9.CHM or VBAWRD10.CHM in your word installation directory.

    Regards

    Thomas
Sign In or Register to comment.