+ Reply to Thread
Results 1 to 25 of 25

Orientation.Landscape - Connect to printer

  1. #1
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Orientation.Landscape - Connect to printer

    I made a macro where I
    - open a Word document
    - copy/paste a Excel table

    I don't need to print the document, it's only to show the data and to give the user the possibility to print or create a pdf (max 5%)

    When I change the orientation of the Word-doc (.PageSetup.Orientation = xlLandscape) then it hangs for a while when the printert is not switched on

    The reason is that Word is trying to "connecting to printer" (the message can be seen in the left bottom corner in blue)

    Thanks for helping me out

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,417

    Re: Orientation.Landscape - Connect to printer

    Welcome to the forum.

    Please share the code that you are using.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Please find the part where it hangs for ±30sec
    Please Login or Register  to view this content.
    Thanks
    Last edited by AliGW; 04-27-2024 at 05:22 AM. Reason: Code tags added - please review the forum guidelines.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,417

    Re: Orientation.Landscape - Connect to printer

    Have you tried stepping through the code yourself to identify where the hang is happening?

    https://www.myonlinetraininghub.com/debugging-vba-code

  5. #5
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Yes,
    I created a Breakpoint just before the line and
    on <F8> you see in the Word document the message in the left bottom corner in blue "connecting to printer".
    More, if the printer is switched on, everything works perfect

  6. #6
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Is there any code to block for "connecting to printer" and once the pagesetup is set
    then to reconnect to the printer?

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,574

    Re: Orientation.Landscape - Connect to printer

    You could try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  8. #8
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Thanks.
    Application.PrintCommunication doesn't solve the problem
    As soon as it arrives at the command "Pagesetup", it hangs for 30'
    As I mentioned, you see a message "connecting to printer, Press ESC to cancel" (the message can be seen in the left bottom corner in blue)
    If you press ESC the macro immediatly continues to run

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,574

    Re: Orientation.Landscape - Connect to printer

    Maybe Application.DisplayAlerts = False

  10. #10
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Thanks.
    The difference is it doesn't show the blue message (Connecting to printer...) at the bottom of the word page but it still hangs

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,574

    Re: Orientation.Landscape - Connect to printer

    All out of ideas.

  12. #12
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,234

    Re: Orientation.Landscape - Connect to printer

    Try programmatically changing the default printer in Word (not Excel) to, for example, Microsoft Print to PDF, then issue a command to change the page orientation and finally restore the default printer.

    Artik

  13. #13
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Thanks Artik.

    The code
    << Application.ActivePrinter = "Microsoft Print to PDF" >>
    gives error 1004 (Method 'activeprinter' of object '_Application' failed

    With the code
    << Application.ActivePrinter = "Microsoft Print to PDF on Ne01:" >>
    I have no error but it doesn't work (it hangs for ± 20 sec)

    I just tried to deactivate the wifi connection. This works perfect.
    ...But I have not the knowledge how to de- and reactivate the wifi connection with vba

    Perhaps you could help me out with that.
    That would solve the whole issue

    Thanks

  14. #14
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,035

    Re: Orientation.Landscape - Connect to printer

    What about

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Thanks.
    This works fine.
    The only disadvantage is that when at the end I reset the active Printer to the default one
    << WA.ActivePrinter = "Brother DCP-L3510CDW series" >> it hangs again

  16. #16
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,035

    Re: Orientation.Landscape - Connect to printer

    Maybe check if it's available first.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Thanks a lot
    This is the solution
    Thanks to everyone who was helpfull to solve the problem
    I appreciate

  18. #18
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,234

    Re: Orientation.Landscape - Connect to printer

    Quote Originally Posted by Helivwe View Post
    The code
    << Application.ActivePrinter = "Microsoft Print to PDF" >>
    gives error 1004 (Method 'activeprinter' of object '_Application' failed
    Both applications (Excel and Word) have the same commands when it comes to setting/reading the active printer. They differ “only” in the way they are called.
    If you ran in Excel code
    Please Login or Register  to view this content.
    then it applies to Excel. And in Excel, to set the active printer, in addition to the name of the printer, you need to specify the name of the port. In Word, the port name is not required.


    Quote Originally Posted by Helivwe View Post
    I just tried to deactivate the wifi connection. This works perfect.
    ...But I have not the knowledge how to de- and reactivate the wifi connection with vba
    Try it, but I do not guarantee success.
    Please Login or Register  to view this content.
    Artik

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,574

    Re: Orientation.Landscape - Connect to printer

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  20. #20
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    I'm sorry.
    I tought it was working with the solution of ByteMarks but I didn't noticed someone switched the printer on.
    The code is perfect, you can change .Orientation = wdOrientLandscape but
    once you set the printer back <<... Then .ActivePrinter = myPrinter>>it hangs because at that time it tries to find the printer:
    It shows the blue message (Connecting to printer...)

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,575

    Re: Orientation.Landscape - Connect to printer

    try
    set Application.PrintCommunication to false and set it back to true at the end.
    e.g
    Please Login or Register  to view this content.
    and see if this runs faster.

  22. #22
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Until now I tried:

    Please Login or Register  to view this content.
    The result of the function <<PrinterOnline(sPrinter$)>> is always True, whether the printer is switched on or not
    On <<.ActivePrinter = myPrinter>> it hangs

  23. #23
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,234

    Re: Orientation.Landscape - Connect to printer

    You said that temporarily disabling WiFi accelerated the execution of the code. Have you tried implementing the code from post #18?


    Still another solution, although a bit inconvenient for the user, might be to switch the active printer programmatically to “Microsoft Print to PDF” without restoring the previous one. The command
    Please Login or Register  to view this content.
    switches the printer for this Word session only (it does not affect the Win sytem settings). The disadvantage of the solution is that when the user actually wants to print the document, he will have to choose the correct printer himself.

    Artik

  24. #24
    Registered User
    Join Date
    04-27-2024
    Location
    Kortrijk
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Orientation.Landscape - Connect to printer

    Thanks.
    The purpose of the macro is to use it for people people who don't know how how to mange those things

    I see as soon as you use the ".PageSetup" it tries to find the printer.
    With “Microsoft Print to PDF” I pospone the problem

  25. #25
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,574

    Re: Orientation.Landscape - Connect to printer

    Maybe store the default printer when you start the Excel workbook. Then give them two buttons. One to adjust the page settings. And the second to restore the default printer and print the document.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] printing on backpage, but changing the orientation to landscape
    By chubbychub in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-24-2023, 06:34 AM
  2. [SOLVED] Set size to A4, orientation to landscape and margins to narrow and then Save As PDF
    By waimea in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2018, 12:03 PM
  3. [SOLVED] Print Orientation from Portrait to landscape?
    By bralew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2017, 07:20 AM
  4. Save Excel Charts to PDF in Landscape Orientation and Fit Page
    By huntethic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2017, 05:55 PM
  5. Print Macro - Landscape Orientation Graph
    By Oliver Rogers in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-28-2011, 07:37 AM
  6. Trouble with landscape page orientation
    By barbinhb in forum Excel General
    Replies: 2
    Last Post: 03-11-2010, 04:17 PM
  7. landscape and letter orientation same doc?
    By godfather_77 in forum Word Formatting & General
    Replies: 1
    Last Post: 02-22-2009, 07:59 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1