Results 1 to 4 of 4

User form linked to Macro to show print preview

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,765

    User form linked to Macro to show print preview

    I have a user form and one of the items is to show the print Preview for several sheets

    when running the macro , I am able to to select "ClosePrint Preview"


    However when running the macro via the user form" it freezes and I need to right click on the task bar for the workbook and select close window

    It would be appreciated if someone could assist me so that the printview using the user form does not freeze and can select the or cancel button to exit




    See User form code below


     Private Sub CancelButton_Click()
    Unload UserForm1
    End Sub
     Private Sub OKButton_Click()
    Application.ScreenUpdating = False
    
    
    If OptionprintPreview Then
    PrintPreview_salesSheets
    End If
    End Sub


    See macro below




     Sub PrintPreview_SalesSheets()
         Dim Sht As Worksheet, C As Range
          Dim iRow As Long
         For Each Sht In ThisWorkbook.Sheets                        'loop through all sheets
              With Sht
                   If .Name Like "sales*" Then                      'check name
                        Set C = .Range("A1").CurrentRegion          'range around A1
                        .ResetAllPageBreaks
                        For iRow = C.Row + 25 To C.Row + C.Rows.Count + 1 Step 25
                             .Rows(iRow).PageBreak = xlPageBreakManual
                        Next
    
                        With .PageSetup
                             .PrintArea = C.Resize(, 21).Address
                             .CenterFooter = "&a      &P of &N  &D &T"
                             .Orientation = xlLandscape
                             .Zoom = 65                             'Set Print Size to 80% of Full Size - otherwise 60 lines per page overflows
                             .FitToPagesWide = 1                    'Put All Columns in the Print Area on One Sheet
                             .FitToPagesTall = 1              'Use as many Pages as necessary
                             .PrintGridlines = True
                        End With
    
                        .PrintPreview                               'Print Preview
                        Application.SendKeys "{ESC}"
                        Application.Goto .Range("A1")
                   End If
              End With
         Next
    
    End Sub
    Last edited by Howardc1001; 12-29-2021 at 04:07 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to enable user to preview print range
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-22-2019, 02:09 AM
  2. Print preview for a User Form OR Select a printer from list of avaiable
    By TheHobbit81 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2019, 06:31 AM
  3. [SOLVED] User form doesn't unload with a print preview in front of it in a code bloc
    By mdovey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2014, 08:24 AM
  4. User Form freezes when I do Print Preview
    By JieJenn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-08-2012, 12:55 PM
  5. Print preview from user form opened from a user form
    By Brunstgnegg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-13-2011, 05:12 AM
  6. VBA Macro shows Print Preview page: How to auto-maximize the Print Preview?
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2010, 04:48 PM
  7. Replies: 2
    Last Post: 04-05-2006, 09:40 PM

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