Solved

using the Excel object and ActivePrinter

Posted on 2003-10-23
2
1,317 Views
Last Modified: 2008-02-01


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.xls")
   
    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?





0
Comment
Question by:corduroy9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
TwistD_PissR earned 100 total points
ID: 9607988
Here is what you can do:
1.) set "Print-2-Image" printer as the Default Printer (only temporary)
2.) Try this (and be sure to write down everything in the MSGBOX
      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.xls")
                msgbox xl.ActivePrinter
            
            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
3.) Set the printer value equal to what appeared in the msgbox
      
      i.e.  xl.ActivePrinter = "Print-2-Image on LPT1"  ' Local Port
            xl.ActivePrinter = "Print-2-Image on Ne01"  ' Network
4.) Run Code and test
5.) Reset default printer to whatever it was before
6.) Done

Explaination:
  In a WIN32 system you have to define where the device is located (local or network) when using
excel's activeprinter funtion

TwistD
0
 
LVL 2

Author Comment

by:corduroy9
ID: 9613472
TwistD,

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!

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month4 days, 13 hours left to enroll

635 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