Help with Print Dialog from Excel

KhanofTarkir

New Member
Joined
Sep 3, 2014
Messages
24
Hi all,

I am having some trouble with the code below - when I run the macro I simply print out 7 duplicate copies of the target range of cells in the first tab as opposed to one copy of the target range of cells for each different individual tab. There are 7 tabs in total in the workbook, so I am guessing that the macro is looping the print dialog 7 times for a single tab. Any help would be greatly appreciated :)

Code:
Sub PrintQC()

Dim book As Workbook
Dim sheet As Worksheet
Dim text As String


Set book = ActiveWorkbook


For Each sheet In book.ActiveSheet


    Range("A1:F23").Select
    ActiveSheet.PageSetup.PrintArea = "A1:F23"
    ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
    :=True
    
Next sheet


End


        
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Sub PrintQC()

Dim book As Workbook
Dim sheet As Worksheet
Dim text As String


Set book = ActiveWorkbook


For Each sheet In book.ActiveSheet
sheet.Activate '<=======================
ActiveSheet.PageSetup.PrintArea = "A1:F23"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True

Next sheet


End



End Sub
 
Upvote 0
Try

Code:
Sub PrintQC()
Dim book As Workbook
Dim sht As Worksheet
Set book = ActiveWorkbook
For Each sht In book.Worksheets
    sht.PageSetup.PrintArea = "A1:F23"
    sht.PrintOut
Next sht
End Sub
 
Upvote 0
Hi BobUmlas and VoG,

Actually, the code works fine but it seems that the printer is still only printing out 7 copies of the range of cells from the first sheet (active sheet). Could you maybe provide some insight into why this might be the case? Thanks!
 
Upvote 0
Hi VoG, with your code it worked for me the first time, but now I receive an error message: Run time error 1004 Method 'Printout' of object '_Worksheet' failed. Do you know why this may be happening?

Thank you.
 
Upvote 0
Hi VoG, yes sorry I should have mentioned that - I do have 2 hidden sheets but I don't believe I have any protected sheets.
 
Upvote 0
Try

Code:
Sub PrintQC()
Dim book As Workbook
Dim sht As Worksheet
Dim h As Boolean
Set book = ActiveWorkbook
For Each sht In book.Worksheets
    h = sh.Visible
    If Not h Then
        sh.Visible = xlSheetVisible
    End If
    sht.PageSetup.PrintArea = "A1:F23"
    sht.PrintOut
    sh.Visible = h
Next sht
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top