Select All Worksheets in Excel VBA

  Desert Andy 18:21 21 Mar 2007
Locked

If I want to select all the worksheets in a workbook to print preview, what code should I use.

Thanks

  VoG II 18:33 21 Mar 2007

Something like

Sheets(Array("Sheet17", "Sheet16", "Sheet15", "Sheet14", "Sheet13", "Sheet12", "Sheet11", "Sheet10")).Select
ActiveWindow.SelectedSheets.PrintPreview

  VoG II 18:38 21 Mar 2007

Or even

ThisWorkbook.Worksheets.Select

  Desert Andy 18:39 21 Mar 2007

The trouble is I don't know how many sheets there are in the workbook, since it is a database, so I wanted to try and select all without naming all the sheets in an array. Any code like select all sheets?

  VoG II 18:40 21 Mar 2007

Yep - just thought of it :o)

  VoG II 18:58 21 Mar 2007

This even better as it avoids Selecting altogether and is one less line of code:

ThisWorkbook.Worksheets.PrintPreview

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

OnePlus 5 review

See the work of famous artists playing with toys

iPad Pro 10.5in (2017) review

Comment faire une capture d’écran sur un Mac ?