+ Reply to Thread
Results 1 to 8 of 8

Macro to Print and suppress Print Dialog Message "Now Printing"

Hybrid View

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

    Macro to Print and suppress Print Dialog Message "Now Printing"

    I have a macro to print from sheet onwards where the value in C29 <>0

    The Macro prints well, but there is a Message dialog box which is an office feature the says "Printing" and below it "Now Printing" This dialog message box appers each time a sheetis being printing

    I would like to suppress this in my code

     Sub PrintChequeAdvices()
    
        Dim ws As Worksheet
        Dim cell As Range
    
        Application.DisplayAlerts = False 'suppress print message
        Application.ScreenUpdating = False 'suppress screen updating
       
    
        For Each ws In Worksheets
            If ws.Index >= 3 And ws.Range("C29").Value <> 0 Then
                With ws.PageSetup
                    .PrintArea = "$A$1:$E$38"
                    .Zoom = False
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                    .Orientation = xlLandscape ' set the page orientation to Landscape
                End With
                For Each cell In ws.Range("A1:E38")
                    cell.Borders.LineStyle = xlContinuous
                    cell.Borders.Weight = xlThin
                Next cell
             
                ws.PrintOut Preview:=False 'print without preview
           
            End If
        Next ws
    
        Application.DisplayAlerts = True 'enable display alerts
        Application.ScreenUpdating = True 'enable screen updating
        
    
    End Sub

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Macro to Print and suppress Print Dialog Message "Now Printing"

    Will need Windows API's coding...Google has lotsa hits...
    Last edited by Sintek; 04-29-2023 at 04:19 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Re: Macro to Print and suppress Print Dialog Message "Now Printing"

    Hi Sintek. Thanks for the advise. This is the dialog box that appears that I want to Suppress
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Macro to Print and suppress Print Dialog Message "Now Printing"


    As nothing exists on Excel side to 'suppress' this window - not sure even generated by Excel - so
    you have to dig out on Web, on OS forums …

  5. #5
    Valued Forum Contributor
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (24 H2) 64 Bit
    Posts
    1,186

    Re: Macro to Print and suppress Print Dialog Message "Now Printing"

    @Howard, you may try this;

    Sub Test()
        Dim myExcel As New Excel.Application, myWB As Workbook, ws As Worksheet
        
        If ThisWorkbook.Saved = False Then ThisWorkbook.Save
        
        Set myWB = myExcel.Workbooks.Open(ThisWorkbook.FullName)
       
        For Each ws In myWB.Worksheets
            If ws.Index >= 3 And ws.Range("C29").Value <> 0 Then
                With ws.PageSetup
                    .PrintArea = "$A$1:$E$38"
                    .Zoom = False
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                    .Orientation = xlLandscape
                End With
                
                With ws.Range(ws.PageSetup.PrintArea)
                    .Borders.LineStyle = xlContinuous
                    .Borders.Weight = xlThin
                End With
             
                ws.PrintOut Preview:=False
            End If
        Next ws
        
        myWB.Close SaveChanges:=False
        myExcel.Quit
        Set myWB = Nothing
    End Sub
    Last edited by Haluk; 04-30-2023 at 03:45 PM.

  6. #6
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Re: Macro to Print and suppress Print Dialog Message "Now Printing"

    Many Thanks Haluk, It works 100%

  7. #7
    Valued Forum Contributor
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (24 H2) 64 Bit
    Posts
    1,186

    Re: Macro to Print and suppress Print Dialog Message "Now Printing"

    Quote Originally Posted by Howardc1001 View Post
    Many Thanks Haluk, It works 100%
    You're welcome and thx for the rep.

  8. #8
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Re: Macro to Print and suppress Print Dialog Message "Now Printing"

    I found this API code for 64 Bit Sytem and adapted it . However, Haluk's Solution is far more simple and works perfectly


     Option Explicit
    
    Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
        
    Private Declare PtrSafe Function IsWindow Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
    
    Private Declare PtrSafe Function InvalidateRect Lib "user32" (ByVal hwnd As LongPtr, _
        lpRect As LongPtr, ByVal bErase As LongPtr) As LongPtr
    
    Private Declare PtrSafe Function UpdateWindow Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
    
    Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
    
    Public Function fncScreenUpdating(State As Boolean, Optional Window_hWnd As LongPtr = 0) As LongPtr
        Const WM_SETREDRAW = &HB
        Const WM_PAINT = &HF
        
        If Window_hWnd = 0 Then
            Window_hWnd = GetDesktopWindow()
        Else
            If IsWindow(hwnd:=Window_hWnd) = False Then
                Exit Function
            End If
        End If
        
        If State = True Then
            Call SendMessage(hwnd:=Window_hWnd, wMsg:=WM_SETREDRAW, wParam:=1, lParam:=0)
            Call InvalidateRect(hwnd:=Window_hWnd, lpRect:=0, bErase:=True)
            Call UpdateWindow(hwnd:=Window_hWnd)
        Else
            Call SendMessage(hwnd:=Window_hWnd, wMsg:=WM_SETREDRAW, wParam:=0, lParam:=0)
        End If
    End Function
    
    Public Sub PrintChequeAdvices()
        Dim ws As Worksheet
        Dim cell As Range
        
        fncScreenUpdating State:=False, Window_hWnd:=GetDesktopWindow()
        Application.DisplayAlerts = False 'suppress print message
        Application.ScreenUpdating = False 'suppress screen updating
        Application.DisplayStatusBar = False 'suppress status bar message
        Application.PrintCommunication = False 'suppress printing messages
        Application.StatusBar = "Printing..." 'suppress printing message bar
        
        For Each ws In Worksheets
            If ws.Index >= 3 And ws.Range("C29").Value <> 0 Then
                With ws.PageSetup
                    .PrintArea = "$A$1:$E$38"
                    .Zoom = False
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                    .Orientation = xlLandscape ' set the page orientation to Landscape
                End With
                For Each cell In ws.Range("A1:E38")
                    cell.Borders.LineStyle = xlContinuous
                    cell.Borders.Weight = xlThin
                Next cell
                Application.StatusBar = "Printing " & ws.Name & "..."
                ws.PrintOut Preview:=False 'print without preview
            End If
        Next ws
    
        Application.DisplayAlerts = True 'enable display alerts
        Application.ScreenUpdating = True 'enable screen updating
        Application.DisplayStatusBar = True 'enable status bar message
        Application.PrintCommunication = True 'enable printing messages
        Application.StatusBar = False 'clear the status bar
        fncScreenUpdating State:=True, Window_hWnd:=GetDesktopWindow()
    End Sub

+ 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. Replies: 2
    Last Post: 10-27-2020, 05:43 AM
  2. Replies: 9
    Last Post: 05-11-2020, 11:05 AM
  3. Printing an area (A1:I272) on a different sheet than the "Print" button is on
    By cmsandiford in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-04-2014, 11:58 AM
  4. Making "Selection" the default in print dialog box?
    By pradhan in forum Excel General
    Replies: 2
    Last Post: 06-05-2010, 11:50 PM
  5. [SOLVED] Suppress "Disable/Enable Macros" and Query Refresh dialog on open
    By Sharon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2006, 05:25 PM
  6. printing multiple print areas with a print dialog box
    By LHaro in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2005, 05:05 PM
  7. [SOLVED] Excel printing problem - won't print cell under a "fill effect" bo
    By dmotika in forum Excel General
    Replies: 0
    Last Post: 05-26-2005, 05:15 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