Results 1 to 20 of 20

Thread: Excel VBA - Turn Off Double Sided Print

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Excel VBA - Turn Off Double Sided Print

    How do I programmatically uncheck the "Print On Both Sides" Checkbox? I've done the "Record A Macro" thing to both check it, and uncheck it, and I can't see one bit of difference in either macro code. Nothing I've tried so far has any effect.
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA - Turn Off Double Sided Print

    i don't believe you can access this directly from vba /vb, you would need to change the default settings for the windows printer, then change back after printing

    i am sure you did not want to hear that.............

    see this thread for code
    http://www.vbforums.com/showpost.php...8&postcount=11

    see this thread for an activex dll
    http://www.vbforums.com/showthread.php?t=564553
    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

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Excel VBA - Turn Off Double Sided Print

    I'm guessing you have no access to the PRINTER object from vba?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA - Turn Off Double Sided Print

    no printers collection, only through api
    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

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VBA - Turn Off Double Sided Print

    Is there a way to tell if it is checked (even though you can't change it?)

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VBA - Turn Off Double Sided Print

    I think I'm going to go with http://www.vbforums.com/showpost.php...8&postcount=11

    The next thing I would need is how to, using Excel VBA, feed the function in the above link the default printer name. In VB6 I would use
    Code:
    Printer.DeviceName
    But, clearly, this is not supported in Excel VBA. What would be the equivalent?

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA - Turn Off Double Sided Print

    activeprinter
    though you need to trim off the port
    left(activeprinter, instr(activeprinter, " on ")-1)

    or you can use the getdefaultprinter API
    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

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VBA - Turn Off Double Sided Print

    Quote Originally Posted by westconn1 View Post
    activeprinter
    though you need to trim off the port
    left(activeprinter, instr(activeprinter, " on ")-1)
    Well, thats intuitive

    Thanks pete.

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VBA - Turn Off Double Sided Print

    Is there something besides this that I need to do
    Code:
    Dim ret As Long
    ret = Setduplex(Left(ActivePrinter, InStr(ActivePrinter, " on ") - 1), 3)
    This didn't work. It caused no errors, but it also didn't turn on double sided printing.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA - Turn Off Double Sided Print

    hmmm
    it would appear that the printer settings are not changed after excel is open, same as going to
    control panel > printers and faxes and changing the properties there
    i am guessing excel reads the state of the properties when it opens then uses those throughout, unless changed within excel

    i tested the code originally using shellexecute, for printing pdfs etc,
    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

  11. #11

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VBA - Turn Off Double Sided Print

    So, basically, we are back to "you can't get there from here", right?

  12. #12

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VBA - Turn Off Double Sided Print

    I even hard coded my printer name into the function and it still didn't work.
    Code:
    ret = Setduplex("\\servername\printername", 3)

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA - Turn Off Double Sided Print

    i found some other articles on this issue, including
    http://support.microsoft.com/kb/828638 which discusses duplex printing in Word, very similar
    and
    another forum that stated that for the code to work you must have enough permissions, and it must be a local printer driver

    the simplest method if it is available to you, is to create an additional copy of the printer, with duplex set as you require, then change activeprinter to that
    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

  14. #14

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VBA - Turn Off Double Sided Print

    Quote Originally Posted by westconn1 View Post
    the simplest method if it is available to you, is to create an additional copy of the printer, with duplex set as you require, then change activeprinter to that
    I could do that for me, but I'm not sure about doing it for 40 or so other people who actually use the application.

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA - Turn Off Double Sided Print

    i did not know if it was possible to install an additional shared printer they all could use
    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

  16. #16
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Excel VBA - Turn Off Double Sided Print

    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  17. #17

    Thread Starter
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel VBA - Turn Off Double Sided Print

    Yes, I did and a couple others like it.

    I didn't try it from Word so I will take it at face value that it works...I can't, however, get it to work in Excel VBA.

  18. #18
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA - Turn Off Double Sided Print

    word does do some printer things differently from excel
    in word
    changing activeprinter in word vba changes windows default printer (word 2000), which is not always desired, changing activeprinter in the printer dialog does not do this
    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

  19. #19
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Excel VBA - Turn Off Double Sided Print

    That code does not change ActivePrinter, but it can change duplex setting on ActivePrinter.
    It can work for both Excel and Word.
    Code:
    '-- iDuplex = 1 : Single-sided printing
    '-- iDuplex = 2 : Duplex printing using a horizontal binding
    '-- iDuplex = 3 : Duplex printing using a vertical binding
    Sub PrintDuplex(ByVal iDuplex As Long)
        Dim iCurDuplex As Long
    
        If iDuplex < 1 Or iDuplex > 3 Then iDuplex = 3
        
        Debug.Print "Current Duplex setting:"; GetDuplex()
        '-- save the current setting
        iCurDuplex = GetDuplex()
        
        If iCurDuplex <> iDuplex Then SetDuplex iDuplex
        Debug.Print "New Duplex setting:"; GetDuplex()
        
        '-- print activesheet
        'ActiveSheet.PrintOut  Copies:=1
        
        '-- restore the original setting
        If iCurDuplex <> iDuplex Then SetDuplex iCurDuplex
        Debug.Print "Restored Duplex setting:"; GetDuplex()
    
    End Sub
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  20. #20
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228

    Re: Excel VBA - Turn Off Double Sided Print

    What am I missing?

    I'm trying to print double-sided from an Excel 2007 sheet when a user presses my Form Control Button.
    Not sure if I should have made a new thread now that I learned that this does not work in newer versions of Excel.

    I modified anhn's
    Code:
    '-- iDuplex = 1 : Single-sided printing
    '-- iDuplex = 2 : Duplex printing using a horizontal binding
    '-- iDuplex = 3 : Duplex printing using a vertical binding
    Sub Custom_Double_Sided_Print_Click()
        Dim iDuplex As Long
        iDuplex = 3
        Dim iCurDuplex As Long
        
        Debug.Print "Current Duplex setting:"; GetDuplex()
        '-- save the current setting
        iCurDuplex = GetDuplex()
        
        If iCurDuplex <> iDuplex Then SetDuplex iDuplex
        Debug.Print "New Duplex setting:"; GetDuplex()
        
        '-- print activesheet
        ActiveSheet.PrintOut  Copies:=1
        
        '-- restore the original setting
        If iCurDuplex <> iDuplex Then SetDuplex iCurDuplex
        Debug.Print "Restored Duplex setting:"; GetDuplex()
    
    End Sub
    And used the module code at http://pubs.logicalexpressions.com/P...cle.asp?ID=116 "Main Code for the Article" in a separate module.

    I added a Debug.Print to SetPrinterProperty's cleanup code and sure enough, the cleanup code is being called which I expect is when it Couldn't access shared printer settings.

    I'm attempting to print to a RICOH Aficio MP C6501, but don't know what other printers may be used.

    I still get single sided from VBA. I can manually set to double-sided by Properties | Print on Both Sides | Flip on ... Edge; which I'd expect corresponds to vertical or horizontal binding.
    Last edited by Phenix; Jul 12th, 2011 at 04:54 PM. Reason: Added 2007
    Circa 1995
    Engineer - I think we should put our website address on our paper catalogs.
    Vice President - Don't get too excited about this internet thing.


    I am sorry, but the Oracle was mistaken. You cannot help us.
    -Matrix video game


    I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. ... and it probably never will support anything other than AT-harddisks, as that's all I have :-(.
    -Linus


    Question. Do you know that the character "?" means I'm asking a question? Question. Do you know that spoken inflection also provides the same cue? So please don't say, "Question" before you ask your question. Believe me I'll know.

    That said, I would have said this first if it had to precede what I'm telling you now. Having said that, what I'm telling you now is the same thing I just said about the annoying phrases "That said" and "Having said that".


    Are you threatening me, Master Jedi?
    -Chancellor Palpatine

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