Results 1 to 7 of 7

Thread: VBA: How to select a printer on the network.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Dear VB users,

    Writing a VBA application, I do have to select a printer on the network.
    Is this possible in VBA

    In VB I am using:

    Dim MyPrinter as Printer
    For each MyPrinter in Printers
    msgbox MyPrinter.DeviceName
    next

    Please can someone give me VBA source and/or information wich references I do have to choose.

    Nice greetings,

    Michelle.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    In both Word and Excel VBA you can use the ActivePrinter property of the Application object.
    Code:
    ActivePrinter = "HP LaserJet 4 local on LPT1:"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Thanks Joacim Andersson.

    I am searching for selecting a printer on a network.

    Is there someone who can help me???

    Nice regards,

    Michelle.

  4. #4
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253
    Here michelle try this.

    dim thisprinter as printer

    for each thisprinter in printers
    if thisprinter.devicename = " " then
    set printer = thisprinter
    exit for
    next

    But also make sure you have the commondialog box on your form.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Thanks jeffro,

    The source you send to me is known for me. I don't understand what you mean with

    "But also make sure you have the commondialog box on your form."

    I placed a "print form" on my form but the source is stumbling over the Dim line.
    Please can you be more clear with your last sentence?

    Nice regards,

    Michelle

  6. #6
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Talking Printers on network

    If you know the printers name and server etc (UNC address) then you can use the api.

    eg printer is \\matt_loc1\mjgprin0012

    Code:
    Declare Function AddPrinterConnection Lib "winspool.drv" Alias "AddPrinterConnectionA" (ByVal pName As String) As Long
    Public Function AddPrinter(ByVal sName$) As Boolean
    
        Dim lRes As Long
        
        lRes = AddPrinterConnection(UCase(sName))
    
    End Function
    There is also a DeletePrinterConnection call.
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  7. #7
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253
    Well if you are using a menu you should also use a commondialogbox. What a commondialog box does is it can bring up the print dialog box and then from there you can choose to print your form. You can find the commondialog box in the components in the project menu in vb. Just click on it and then apply the component. If have any more questions just email me at [email protected].

    Sorry about being unclear earlier!!

Posting Permissions

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



Click Here to Expand Forum to Full Width