Results 1 to 4 of 4

Thread: VBA, office, VBS or shell duplex printing

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    VBA, office, VBS or shell duplex printing

    as there is no provision to change duplex in vba or when using shell /shellexceute etc
    here is a dll to return /set duplex property for the printer, it should always be returned to the original state after printing, i am posting the dll as users for vba can not compile the code

    sample usage
    vb Code:
    1. Set pd = CreateObject("printerduplex.class1")
    2. ret = pd.duplex("HP Color LaserJet 2605", 0)  ' get current state, pass 0
    3. success = pd.duplex("HP Color LaserJet 2605", 2)  'set to flip side, returns true or false
    4. ' 1 = single side, 3 = flip top
    5. 'printing here
    6. success = pd.duplex("HP Color LaserJet 2605", ret)  ' return to original state

    i have updated the dll with an extra function, to return a list of all available printers, with the port ("ne01") needed for excel etc
    printerlist = pd.listprinters
    Attached Files Attached Files
    Last edited by westconn1; Apr 6th, 2009 at 07:46 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  2. #2
    New Member
    Join Date
    Mar 2010
    Posts
    2

    Re: VBA, office, VBS or shell duplex printing

    Quote Originally Posted by westconn1 View Post
    as there is no provision to change duplex in vba or when using shell /shellexceute etc
    here is a dll to return /set duplex property for the printer, it should always be returned to the original state after printing, i am posting the dll as users for vba can not compile the code

    sample usage
    vb Code:
    1. Set pd = CreateObject("printerduplex.class1")
    2. ret = pd.duplex("HP Color LaserJet 2605", 0)  ' get current state, pass 0
    3. success = pd.duplex("HP Color LaserJet 2605", 2)  'set to flip side, returns true or false
    4. ' 1 = single side, 3 = flip top
    5. 'printing here
    6. success = pd.duplex("HP Color LaserJet 2605", ret)  ' return to original state

    i have updated the dll with an extra function, to return a list of all available printers, with the port ("ne01") needed for excel etc
    printerlist = pd.listprinters
    Hi

    How to connect this dll to excel VBA? What are the arguments?

  3. #3
    New Member
    Join Date
    Mar 2010
    Posts
    2

    Re: VBA, office, VBS or shell duplex printing

    Quote Originally Posted by brixon View Post
    Hi

    How to connect this dll to excel VBA? What are the arguments?

    I've got it:

    On Microsoft Visual Basic for Application Editor:
    Tools->References...
    Button Browse... and show the path to dll.

    Another problem - i've got printers with and without duplex. On printers without duplex, dll show message box, that this printer doesn't support duplexing, but on those with duplex function, state of duplex is changing from 1 to 3, but the printers doesn't print in duplex, my printers are:
    NRG DSM 645, infotec 2230.

    Maybe those settings apply only for HP printers?

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA, office, VBS or shell duplex printing

    i have other reports that it is not working correctly in excel, but have not found any solution as yet
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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