Select All Worksheets in Excel VBA

  Desert Andy 18:21 21 Mar 2007

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


  VoG II 18:33 21 Mar 2007

Something like

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

  VoG II 18:38 21 Mar 2007

Or even


  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:


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

Elsewhere on IDG sites

Dell XPS 13 9370 (2018) review

The art of 'British' pulp fiction

Best password managers for Mac

TV & streaming : comment regarder le Tournoi des Six Nations 2018 ?