LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Selecting multiple sheets to print to PDF

Eric_G wrote on 5/10/2010 :
To do this task the sheets MUST be grouped AND you must use
ActiveWindow.SelectedSheets as per my example. I don't see a problem
with the way you're grouping (other than the sheetnames are
hard-coded), so the issue lies in how you are "printing" to PDF. The
only way I know how to do this is to use a PDF printer that's already
installed. I realize MSO apps now have the ability to do what you're
trying to do here, but experience tells me to never rely on such things
to process problem free, and so I avoid using them. (Sounds to me like
the export to PDF doesn't work any better than their export to HTML<g
-There are VB PDF 'wrappers' available that do a better job, and
provide output options<g)

I was trying to find a more robust version of the GroupSheets() sub I
posted earlier but was unable to do so at the time. I eventually found
it inside an a client's plugin.xla that allows running admin utilities
inside the main addin. I've pasted it here. This is a well documented,
reusable procedure you can use to group sheets in one of two ways: you
can specify which sheets in a Wkb to include, which will group only the
sheets you specify; -OR- you can specify which sheets to exclude, which
will group all sheets in the workbook except the ones you specify. The
sheetnames aren't hard-coded, which makes it convenient to change the
grouping depending on what you want to do with the group. (In this
client's case, they were generating new workbooks to attach to emails
being sent to various places that only required certain sheets)

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
' GroupSheets()
' This procedure requires only the necessary amount of coding be used
' in the Caller. By default, it requires passing only the first arg.
' Use Example: GroupSheets "Sheet1,Sheet3"
' creates a group of only those sheets.
' To group all sheets in a workbook except those sheets:
' GroupSheets "Sheet1,Sheet3", False
' You can pass the Wkb arg to specify any open workbook.
' (The Wkb doesn't need to be active for this purpose)
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Sub GroupSheets(sSheetnames As String, _
Optional bInGroup As Boolean = True, _
Optional Wkb As Workbook)
' Groups sheets in Wkb based on whether sSheetnames are to be included
or excluded.
' sSheetnames is a comma delimited string. (ie: "Sheet1,Sheet3")

Dim Shts() As String, sz As String
Dim i As Integer, wks As Worksheet, bNameIsIn As Boolean

i = 0
If Wkb Is Nothing Then Set Wkb = ActiveWorkbook

For Each wks In Wkb.Worksheets
bNameIsIn = (InStr(sSheetnames, wks.name) 0)
sz = ""
If bInGroup Then
If bNameIsIn Then sz = wks.name '//includes Sheet in group
Else
If Not bNameIsIn Then sz = wks.name '//excludes Sheet from group
End If
'Build the array
If Not sz = "" Then
ReDim Preserve Shts(0 To i)
Shts(i) = sz
i = i + 1
End If
Next
'Select the array
ActiveWorkbook.Worksheets(Shts).Select
End Sub

Use Example:

Sub SomeProc()
'...//do stuff

GroupSheets "Sheet1,Sheet3"

With ActiveWindow.SelectedSheets
'do PageSetup
'...

'Print or PrintPreview
.PrintOut Copies:=1, Preview:=True, _
ActivePrinter:="PDF_PrinterName"
End With
End Sub

HTH
Garry


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting multiple sheets jday Excel Programming 3 February 13th 09 04:58 PM
Selecting Multiple Sheets in VBA Gizmo63 Excel Worksheet Functions 4 May 8th 06 01:50 PM
selecting multiple sheets Dennis Excel Programming 2 January 1st 04 08:06 PM
selecting multiple sheets Young-Hwan Choi Excel Programming 2 November 24th 03 01:19 AM
Changing the value in multiple sheets without selecting those sheets herm Excel Programming 3 October 14th 03 03:50 PM


All times are GMT +1. The time now is 03:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"