Results 1 to 2 of 2

Excel Freezes During Print Macro

Threaded View

  1. #1
    Registered User
    Join Date
    12-19-2014
    Location
    Portland, Oregon
    MS-Off Ver
    MS Office 2013 32-bit
    Posts
    6

    Excel Freezes During Print Macro

    Hey, I've tried tons of solutions and browsed the web for more for hours now. Maybe one of you can help.

    I have a macro that selects all sheets with a specific string in their name, then prints them. If there are too many sheets, it freezes, and you are unabled to break the macro to debug, and Ctrl+Alt+Del is the only way out. It freezes at different locations each time too...

    My original code:
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Dim x As Integer
        For x = 1 To Worksheets.count
            If VBA.InStr(Worksheets(x).Name, "Lateral Assessment") > 0 Then
                With Worksheets(x).PageSetup
                    .Orientation = xlPortrait
                    .Zoom = False
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                End With
                Worksheets(x).PrintOut
            End If
        Next x
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    I have tried, per other forum threads, the following:
    • Adding DoEvents in the loop to allow the system time to process
    • Adding a "Wait" timer to give it time to process
    • Looping through and setting the pagesetup properties first, then printing (it finishes the loop to set pagesetups fine, but freezes in the print loop like "normal"
    • Moved to adding all of the sheets to an array, then sending them as a single print job (it still freezes after 14-16 pages)

    I also at one point added a progress bar I use in a lot of my bigger processes, and you can see it progressing through the count before freezing on an inconsistent sheet number. Additionally, note that the problem occurs even if I run it one iteration at a time from the VBA code window, thus, it appears that it is not related to processing time (although one cannot be certain of that).

    My current code:
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Dim x As Long, iTotal As Long, sSheets() As String
        iTotal = -1
        For x = 1 To Worksheets.count
            If VBA.InStr(Worksheets(x).Name, "Lateral Assessment") > 0 Then
                With Worksheets(x).PageSetup
                    .Orientation = xlPortrait
                    .Zoom = False
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                End With
                iTotal = iTotal + 1
                ReDim Preserve sSheets(iTotal)
                sSheets(iTotal) = Worksheets(x).Name
            End If
        Next x
        If iTotal <> -1 Then
            Sheets(sSheets).PrintOut Copies:=1, Collate:=True
        End If
        
        Application.ScreenUpdating = True
        Application.EnableEvents = True
    Any idea why this is happening, and possible solutions that I havent tried?
    Last edited by dboatman_z; 01-22-2015 at 05:52 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. excel freezes after updating cells and runing macro
    By sfcleon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-08-2013, 03:06 PM
  2. [SOLVED] Print Preview Freezes my code
    By RedPen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-20-2012, 07:54 PM
  3. 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
  4. Simple macro (ClearContent) freezes Excel
    By bokodilaszlo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-08-2006, 09:24 AM
  5. Macro freezes up Excel
    By Jon Delano in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2005, 03:05 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