No announcement yet.

[Solved] Printing: Error 1004 when attempting to set ActiveP

This topic is closed.
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Solved] Printing: Error 1004 when attempting to set ActiveP

    I have a VB project, where for years, the code internally referenced the Excel object. So when setting the ActivePrinter property of the Application object it was simply a matter of assigning the property like such:

    Set xlApp = New Excel.Application
    xlApp.ActivePrinter = strPrinterName

    Now I have to deploy the same application to various platforms. The primary is a Windows 95 (yeah I know... most us can't even remember what it looks like), and also to Win2K and WinXP. The Win95 platforms runs Office 97, the Win2K platform runs Office 2K, and WinXP runs Office 2003. The development machine runs the Win2K/Office2K combo.

    So to save stuffing about I changed the code the create the Excel object using CreateObject and removed the internal reference. So the code now looks like this:

    Set xlApp = CreateObject("Excel.Application")
    xlApp.ActivePrinter = strPrinterName

    Now for some odd reason M$ have made the ActivePrinter property read-only when the Application object is instantiated using CreateObject. I now get the error:
    "Unable to set the ActivePrinter property of the Application class".

    Does anyone know a work-around for this problem? I can't just assume the ActivePrinter property is defaulted to the correct printer, because the program sets the printer based on whether the report it has to print is in colour or just black-and-white. Save compiling the application on each target platform and changing the referencing back to internal, I don't know what to do.

    Can anyone help?

  • #2
    The ActivePrinter property of the Application class is read-only when the object is instantiated using CreateObject. To get around this problem you can pass the printer in as an option when calling the PrintOut method:

    xlWorksheet.PrintOut ActivePrinter:=strPrinterName

    NB. This is not the case with the Word application class. The ActivePrinter property can be set (is not read-only) at runtime when the Application class has been instantiated using CreateObject. Go figure!


    • #3
      I have read several of the many posts that are on this forum and think that perhaps this is the first one where the person posting the question also was the person answering the post!!

      As far as your solution, how typical of M$ to "standardize" their applications differently!

      Brandtrock Consulting | Brandtrock Files | ISU Athletics | Bricktown | VBA Express