Hi,
This is the code I execute in a loop. For example ... this will be run 3-4 times to loop in a dataset.
VB Code:
objWord = CreateObject("Word.Application") objWord.ActivePrinter = "My Printer Name" objWord.Visible = False Select Case strDocument Case ANNEXEAF With objWord .Documents.Open("C:\Projets\\MyDocument.dot") .ActiveDocument.Bookmarks.Item("siPOCKET").Select() 'word doc bookmark .Selection.Text = clsClass.NoPermis .ActiveDocument.Bookmarks.Item("siDATE").Select() 'word doc bookmark .Selection.Text = clsClass.DateInfrac .PrintOut(Copies:=1, Collate:=True, Background:=True, PrintToFile:=False) 'Wait for document to print Do While .BackgroundPrintingStatus > 0 Application.DoEvents() Loop .Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges) End With
For the 1st document it's ok.
But then it kind of freeze. When I run it line by line (debugging), the application goes fine.
But if I'm not in debug mode, something is going wrong. The only thing I can see is the Do While .BackgroundPrintingStatus loop.
I have to move the mouse or do something else on my PC to make to program continue between each document to print.
And my application window "flikkles" .. as if we were seeing a Word window open, but I want that to happen in the background.
Thanks for helping !




Reply With Quote