LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I print a Word document using ActiveX

Solved!
Go to solution

Hi Zach,

 

Its not continually throwing errors at all. It just does not print anything using codes 2,3,4. Its as if 0 pages are sent to the printer as the printer queue acknowledges that something was sent.

I only see errors if I use the wrong data format on an input and I've got all that figured out.

 

I've decided to bite the bullet and reinstall V2011 and try again.

 

Will let you know tomorrow how that goes.

 

Chris

 

0 Kudos
Message 21 of 31
(2,905 Views)

Hi Zach,

 

I installed LV2011 and ran the .vi once again. The results are the same.

I suspect something is different in Word 2010.

Is there anyone at NI who could help out with that?

Is there any other way besides ActiveX to print a Word document?

 

For selection 1, it is sending a command to print a blank page.

If I send this to file, then there are some print commands in the file.

 

For selections 3 and 4, it seems to be sending an empty file to the printer. (no commands to print anything) no paper comes out of printer.

I can send the print to file and the file will also be empty.

 

Chris

 

0 Kudos
Message 22 of 31
(2,900 Views)

Attached is the VI I would use.

 

The important thing with anything ActiveX is to read the Microsoft documentation and example.

 

From their website, it doesn't appear to be necessary to wire anything to the Pages parameter, but you *must* set Range to 3 and you must set values for From and To.

http://msdn.microsoft.com/en-us/library/ff840681.aspx

 

 

 

Message 23 of 31
(2,899 Views)
Your VI ran perfectly on my Word 2010 with just one modification. The Range input needs to be an integer and not a string. Most enum type selectors including WdPrintOutRange are integers. The only reason that strings are used for the page inputs is to allow for section specifications (ie. S1 to S3).
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.1, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 24 of 31
(2,897 Views)

@michael Munroe wrote:
Your VI ran perfectly on my Word 2010 with just one modification. The Range input needs to be an integer and not a string. Most enum type selectors including WdPrintOutRange are integers. The only reason that strings are used for the page inputs is to allow for section specifications (ie. S1 to S3).

Duh!  My bad.

 

 

0 Kudos
Message 25 of 31
(2,893 Views)
Solution
Accepted by topic author CDreike1

I would like to thank everyone for their persistance in helping me with this problem, particularly Zach.

 

The problem now seems to be in Word itself.

By chance this morning I tried to print a single page and pages from Word itself and the print function failed in the same was as it is from my ActiveX print.vi. The system reports that a file has been sent to the print, however it is an empty file.  I suspect that there is something in my doc file that is causing this error.

 

Best regards,

Chris

 

 

 

0 Kudos
Message 26 of 31
(2,888 Views)

In your VIs, you did not close all your references. If you look at the VI I attached previously, you will see that all the references are closed.

 

The problems you are seeing may be that an existing instance of Microsoft Word is still running.

Check the Task Manager.

 

 

0 Kudos
Message 27 of 31
(2,883 Views)

I got access to a machine with word 2010 and LabVIEW 2011 and was able to print the pages I specified. 

I'm wondering if it has something to do with the file you're trying to print. It looks like its a .dot file not a word document.

Have you tried a just using a .docx file? 

Applications Engineer
National Instruments
CLD Certified
0 Kudos
Message 28 of 31
(2,878 Views)

Thanks for all the input.

As for having another instance of Word running, I don't have one. Checked the Task Manager.

 

Here is the problem:

The document I have to use in this application contains many sections. it was created in Word 2000 or 2003. I've now been told by others here that there is quite a problem in trying to print individual pages once sections have been introduced into a document. The sections are used to separate header and footers so that different headers and footers may be used throughout the document.

 

I will a create multi section document in Word 2010 and see if that solves the problem. I suspect it may not. There may simply be a bug in Word that causes what I'm seeing.

I will post back in a day or two with the results.

 

Thanks All !!

Chris

 

0 Kudos
Message 29 of 31
(2,868 Views)

One more little tidbit:

 

When trying to print from within Word itself, I see exactly the same problems.

I can print the entire document or the current page. I cannot selectively print a specific page or page from a section. If I try, an empty file is sent to the printer and not even a blank page is printed.

 

Regards,

Chris

 

0 Kudos
Message 30 of 31
(2,867 Views)