R
richard.feng
I developed an application using VBA addin managed extension in C#.
Currently i face a problem that Excel can't switch tray when printing a
multi-section report.
(I don't want to use SendKey method in VBA. It is a dirty and
troublesome approach to the problem. I tried before, it doesn't work
and the result is even worse)
So I wrote the switching tray process in Win32(C) API, then it
inter-operates with C# code in my managed COM object for the
automation. But some worksheets still printed from the wrong tray.
After research I found that I used Wn32's SetPrinter function which
globally changed the printer's setting. And if some jobs haven't been
printed out, the rest of the worksheet will print from the wrong tray.
Moreover, using threading sleeping method to pause the print job does
not really work because I can't predict a printer job when it will be
finished. I tried EnumJobs to detect the number of printer jobs before
switching the tray, but without any success.
So after, I decided to use Win32's DocumentProperties to change printer
settings per application. However, I found that documentproperties
would not take effect if I don't rewrite the HDC paint code. Obviously,
it is not possible for me to rewrite Excel Printout function using HDC
approach.
Then the last choice i found is that I might be able to set up multiple
drivers with different tray set up on each driver. But it also didn't
work because Windows prevents me from installing multiple printer
drivers.
I am totally desperate, now. Can anyone give me some ideas on solving
my problem, even recommendation I will take it. (Sorry that I don't
want to hear anything about SendKeys approach to solve this problem.
But if you insist the SendKeys function with very unique method, I will
give a try as well.![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Many thanks to all
Richard
Currently i face a problem that Excel can't switch tray when printing a
multi-section report.
(I don't want to use SendKey method in VBA. It is a dirty and
troublesome approach to the problem. I tried before, it doesn't work
and the result is even worse)
So I wrote the switching tray process in Win32(C) API, then it
inter-operates with C# code in my managed COM object for the
automation. But some worksheets still printed from the wrong tray.
After research I found that I used Wn32's SetPrinter function which
globally changed the printer's setting. And if some jobs haven't been
printed out, the rest of the worksheet will print from the wrong tray.
Moreover, using threading sleeping method to pause the print job does
not really work because I can't predict a printer job when it will be
finished. I tried EnumJobs to detect the number of printer jobs before
switching the tray, but without any success.
So after, I decided to use Win32's DocumentProperties to change printer
settings per application. However, I found that documentproperties
would not take effect if I don't rewrite the HDC paint code. Obviously,
it is not possible for me to rewrite Excel Printout function using HDC
approach.
Then the last choice i found is that I might be able to set up multiple
drivers with different tray set up on each driver. But it also didn't
work because Windows prevents me from installing multiple printer
drivers.
I am totally desperate, now. Can anyone give me some ideas on solving
my problem, even recommendation I will take it. (Sorry that I don't
want to hear anything about SendKeys approach to solve this problem.
But if you insist the SendKeys function with very unique method, I will
give a try as well.
Many thanks to all
Richard