?
Solved

Problem Printing VB.NET Reports with Excel 2003 "PrintOut method of Workbook class failed"

Posted on 2006-05-01
5
Medium Priority
?
477 Views
Last Modified: 2008-02-01
Hi Experts,

I am at a loss with the problem I am having lately.  I am trying to print an excel worksheet to file with acrobat distiller.  I can set the printer with no problem, checked that it was correct.  But, when attempting to print to file, I get the error "PrintOut method of Workbook class failed."  I suppose it could be a COM object or reference that I am missing, but that would be surprising considering I can manipulate all aspects of the excel worksheet without any problems.  The only time I get this error is when I try to print to file.  Using just ".Printout" works fine.  The line of code that causes the error is below.  It worked fine until I had to reformat and reinstall visual studio 2000.

WORKS FINE:
objWksht.Printout()

CAUSES ERROR:
objWksht.Printout(PrintToFile:=True, PrToFileName:=SavePath & "\FILENAME.prn")

The reason I cannot use the ".Printout" method is because this is in a loop creating several files and I cannot have the user needing to type in the file name every time.

Thanks, Experts,
Ren
0
Comment
Question by:Ren
  • 3
  • 2
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 16577827
Hi Ren,

not sure if this goes for VB too but in C# you need to pass null references for all optional params if you do not use them, so i''ve not tried this but you could give it a try

.PrintOut(Nothing, Nothing, Nothing, Nothing, Nothing, True, Nothing, SavePath & "\FILENAME.prn")

hope this helps a bit
bruintje
0
 

Author Comment

by:Ren
ID: 16578835
Thanks very much for the suggestion, bruintje.  Would have been nice if it were that simple.  Unfortunately it didn't do the trick.

Ren
0
 
LVL 44

Accepted Solution

by:
bruintje earned 2000 total points
ID: 16579364
took me a while, knew the problem forgot the solution :)

have no printer installed but this came through in my test

objSh.PrintOut(Reflection.Missing.Value, Reflection.Missing.Value, Reflection.Missing.Value, Reflection.Missing.Value, Reflection.Missing.Value, True, Reflection.Missing.Value, "c:\test.prn")
0
 

Author Comment

by:Ren
ID: 16580243
Ah Ha!  I tried your print string as a test.  When the printout to my C drive folder worked, I started to wonder if it was something other than my excel connection.  So, I paused and made excel visible when the print error occurred.  Then I tried the line of code, modified to run that printout command in the immediate window of Excel's VBA editor.  Same error, but an additional message about an acrobat distiller error.  When I looked back on my SavePath variable, I noticed I had commas in this particular folder name.  Since commas often cause problems, I changed them to dashes and boom, printed without any problem.  Good to know!

You got me started looking elsewhere, full points to bruintje.  Thanks!

-Ren
0
 
LVL 44

Expert Comment

by:bruintje
ID: 16580301
i'm not sure if leaving out the missing.value is a problem or not, it didn't work on my machine without them

though your error clearly came from something else, thanks for the grade :)


0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question