Link to home
Get AccessLog in
Avatar of michman222
michman222

asked on

Printing in the Background

I would like to know the best way to code an application to automatically launch MSWord, print a document and close the application.  The operation needs to happen in the background as much as possible and I don't want to use SendKeys.
I have been looking at ShellExecute. I can get it to open an application  but I can't get it to print.
Any Ideas would be greatly appreciated.
Avatar of TSO Fong
TSO Fong
Flag of Sweden image

How are you using ShellExecute? I'm guessing that you're using "Open" rather than "Print" for the second parameter.


Try your call like this:

SW_SHOWNORMAL = 1

strPath = "C:\"
strFile = "Test.doc"
lngReturn = ShellExecute(Me.hwnd, "Print", strFile, "", strPath, SW_SHOWNORMAL)


This will open Word long enough to print the file, then close Word.

While Word opens and prints, it is visible.

These are the constant options for the last parameter:

SW_HIDE = 0;
SW_MAXIMIZE = 3;
SW_MINIMIZE = 6;
SW_NORMAL = 1;
SW_RESTORE = 9;
SW_SHOW = 5;
SW_SHOWDEFAULT = 10;
SW_SHOWMAXIMIZED = 3;
SW_SHOWMINIMIZED = 2;
SW_SHOWMINNOACTIVE = 7;
SW_SHOWNA = 8;
SW_SHOWNOACTIVATE = 4;
SW_SHOWNORMAL = 1;


Descriptions are:
SW_HIDE:    Hides the calling window while opening the new one.
SW_MAXIMIZE:    Maximizes the target window.
SW_MINIMIZE:    Minimizes the target window.
SW_RESTORE:    Restores the target to its previous state.
SW_SHOW:    Activates the open window in current position.
SW_SHOWDEFAULT:    Show state is based on STARTUPINFO structure.
SW_SHOWMAXIMIZED:    Opens the window maximized.
SW_SHOWMINIMIZED:    Opens the window minimized.
SW_SHOWMINNOACTIVE:    Opens the window to the most recent state without focus.
SW_SHOWNA:    Opens the window without focus.
SW_SHOWNORMAL:    Opens or restores a window to it's most recent state.



Hope this helps. -- b.r.t.
michman222 --

Sorry. I didn't notice that this was a duplicate until after I posted here. Please go ahead and request deletion of this question.

To anyone else --

This is a duplicate posting. I didn't notice the original until I posted here.

If you wish to contribute, you might want to go to https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10355204 .

ASKER CERTIFIED SOLUTION
Avatar of csameer1
csameer1

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access