Home |
Search |
Today's Posts |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Selecting multiple sheets | Excel Programming | |||
Selecting Multiple Sheets in VBA | Excel Worksheet Functions | |||
selecting multiple sheets | Excel Programming | |||
selecting multiple sheets | Excel Programming | |||
Changing the value in multiple sheets without selecting those sheets | Excel Programming |