corduroy9
asked on
using the Excel object and ActivePrinter
I am getting an error when trying to set the ActivePrinter using Excel (9.0 object library). I'm on W2000 using VB6.
Here is my code in a test project:
Private Sub Timer1_Timer()
Timer1.Enabled = False
fnPrintExcelTest
End Sub
Function fnPrintExcelTest()
On Error GoTo Error_Handler:
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Set xl = New Excel.Application
Set wb = xl.Workbooks.Open("c:\test
xl.ActivePrinter = "Print-2-Image" 'Name of the printer i wish to use ' ERROR HERE!!!!!!!!!!!!!!!!!!
wb.PrintOut
wb.Close SaveChanges:=False
xl.Quit
Set xl = Nothing
Error_Handler:
If Err.Number <> 0 Then
MsgBox CStr(Err.Number) & ": " & Err.Description
End If
End Function
The error that I get is: "1004: Application-defined or object-defined error"
A few things to note...
-- I am using Print-2-Image as the printer, so the Excel file will be saved as a TIF.
-- I can do the same exact thing using the Word 9.0 object library and get no problems.
-- When I debug this code, on the line that errors, when I hover on the ActivePrinter, it says "unknown printer (check your Control Panel)" pretty odd message there
-- I can manually open my test file in Excel and print it. It does find Print-2-Image and creates the expected tif...
although, if I open the Print... diaolg window, there is no default printer, but i can choose Print-2-Image from a list
Anyone have a clue on this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm accepting your answer, but I think I had other issues that were screwing up my program. I was trying to print from Word, PowerPoint, and Excel object in the same project and they seemed to conflict with each other, especially with the Printer stuff.
So what I did is kinda hokey...I'm doing a SaveAs on the Excel file to make it a txt file, then opening it in Word to print, Word which seems to be the most stable. Doing something similar with PowerPoint also.
thanks!