3
votes

Let's say that I have a workbook with 3 worksheets, "Sheet 1", "Sheet 2", and "Sheet 3". Now I want to print only "Sheet 1" so in VBA I used

Sheets("Sheet 1").PrintOut

But the macro still print all 3 worksheets. What happened that cause it to print all 3 sheets when I specifically write the code to only print 1?

Activesheet.Printout 'also print all worksheets.

I'm using: Microsoft Excel Professional Plus 2010

1
What version of Excel? - Chrismas007
Hope this is what you're looking for: Microsoft Excel Professional Plus 2010, 14.0.7128.5000 - Kev
Check out the documentation because your syntax looks correct. Maybe you have some sort of funky print range that is set to print all 3 sheets. - Chrismas007

1 Answers

1
votes

Try this and let me know if it works for you.

Sub PrintTest()
    Dim sh As Worksheet
    For Each sh In ThisWorkbook.Worksheets
        If sh.Name = "Sheet1" Then
            sh.PrintOut Preview:=False, ActivePrinter:="NameOfPrinter", PrintToFile:=True, PrToFileName:=PSFileName
        End If
    Next sh
End Sub