My solution to this is to use the following command:
start /min winword <filename> /q /n /f /mFilePrint /mFileExit
This allows the user to specify a printer, no. of copies, etc.
Replace <filename>
with the filename. It must be enclosed in double-quotation marks if it contains spaces. (e.g. file.rtf
, "A File.docx"
)
It can be placed within a system call as in:
system("start /min winword <filename> /q /n /f /mFilePrint /mFileExit");
Here is a C++ header file with functions that handle this so you don't have to remember all of the switches if you use it frequently:
/*winword.h
*Includes functions to print Word files more easily
*/
#ifndef WINWORD_H_
#define WINWORD_H_
#include <string.h>
#include <stdlib.h>
//Opens Word minimized, shows the user a dialog box to allow them to
//select the printer, number of copies, etc., and then closes Word
void wordprint(char* filename){
char* command = new char[64 + strlen(filename)];
strcpy(command, "start /min winword \"");
strcat(command, filename);
strcat(command, "\" /q /n /f /mFilePrint /mFileExit");
system(command);
delete command;
}
//Opens the document in Word
void wordopen(char* filename){
char* command = new char[64 + strlen(filename)];
strcpy(command, "start /max winword \"");
strcat(command, filename);
strcat(command, "\" /q /n");
system(command);
delete command;
}
//Opens a copy of the document in Word so the user can save a copy
//without seeing or modifying the original
void wordduplicate(char* filename){
char* command = new char[64 + strlen(filename)];
strcpy(command, "start /max winword \"");
strcat(command, filename);
strcat(command, "\" /q /n /f");
system(command);
delete command;
}
#endif