Results 1 to 4 of 4

Thread: Printer Choice

  1. #1
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Unanswered: Printer Choice

    All,

    Does anyone have a link to a good example of how to call a printer in VBA?

    The HOWTOs all say this code should work:
    Code:
    Sub SetPrinter(DevName)
        Dim objPrinter
    '    Dim objPrinter as Printer
    '    Set Application.Printer = objXL.Application.Printers(0)
        Set objPrinter = objXL.Application.Printer
    '    For Each objPrinter In objXL.Application.ActivePrinter
    '    For Each objPrinter In objXL.Application.Printers
        For Each objPrinter In Application.Printers
            If objPrinter.DeviceName = DevName Then
                Set Printer = objPrinter
                Exit For
            End If
        Next
        Set objPrinter = Nothing
    End Sub
    But always error with:
    Object doesn't support thsi property or method
    When I try to use the:
    Dim objPrinter as Printer
    I get the error:
    User-defined type not defined
    so everything goes whack after that.

    Open to inputs!!

    Thanks!

    DBS4M

  2. #2
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Partial Fix

    All,

    Found part of my problem. I'm trying to use the routine in VBA for both Access and Excel. They do not handle the same.

    Access loves the "Dim objPrinter as Printer" but Excel hates it.

    Need a way to make a routine that satisfies both.

    DBS4M

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Excel and Access may both be Ofice Apps and both may use VBA but they have a different object notation. some of that dates back to the origins of each app, some of that is for legacy reasons (Excel is a far older app than Access and Access was bought into Microsoft whereas Im pretty certain Excel is a Microsoft product from day one).

    so I don't understand why you feel you
    Need a way to make a routine that satisfies both
    they are different animals with different workings under the skin

    I suppose you could write a wrapper function which mimics, say, the Access process but internally it talks to excel in a way that excel understands
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    Central to split

    H,

    I at least need a subroutine that takes the input and decides which routine actually sets up the printer to print and executes it.

    The printer is "PrimoPDF" which converts the doc to .PDF file for printing, etc. but in one app Access is creating the .xls from an xlt file, then printing it. Here most of the code works fairly well.

    The other (field app) the .xls file (from .xlt template) has a "Save" button, which saves the file and then calls the printer to also save the .pdf version of the file.

    Hope that explains it better.

    Thanks!

    DBS4M

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •