I have a macro that creates a single PDF file of several worksheets of a workbook and saves it in a folder selected by the user. The array of worksheets varies according to an initial selection by the user. The arrays of sheet names to be included in the PDF are maintained in tables inside the workbook. Once the sheet names are selected as an array they are saved as a single document using the ExportAsFixedFormat VBA command.
The macro is run by different users - some using Excel 2010 for Windows and some using Excel 2011 for Mac. The macro works fine on Excel 2010 (Windows). On Excel for Mac, although the array of sheet names is created correctly only the last sheet in the array is saved in the selected folder. Here is the relevant portion of the code:
Sub PrintDiv(ReportMonth, ReportDiv)
' Set up correct title page
Sheets("Title").Select
Range("A23").Value = ReportDiv & " "
Range("A25").Value = ReportMonth & ", 2013"
' Select sheets to print
'
Dim strPath As String, strFileName As String, ReportSheetList As String
Dim y As Integer
Dim WkstNames() As Variant 'declares a dynamic array of sheet names
Dim iWkstCount As Integer
If ReportDiv = "Company" Then ReportSheetList = "ReportCoPDFsheets"
If ReportDiv = "Commercial" Then ReportSheetList = "ReportCommPDFsheets"
If ReportDiv = "Federal" Then ReportSheetList = "ReportFedPDFsheets"
iWkstCount = Range(ReportSheetList).Rows.Count - 1 ' finds the array size (i.e. number of sheets)
'Place worksheet names into a dynamic array for reference using ExportAsFixedFormat
Redim WkstNames(1 To iWkstCount) 'declares the array variable with the appropriate size
Sheets("TOC").Select
Range(ReportSheetList).Select
For y = 1 To iWkstCount
WkstNames(y) = ActiveCell.Offset(y, 0).Value
Next y
Sheets("Title").Select 'tell the export to use this sheet and ignore TOC sheet
Sheets(WkstNames).Select (False) 'pick up all sheets to be saved as PDFs
'Select file save location from user
If OS = "Win" Then
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
strPath = .SelectedItems(1)
End If
End With
strPath = strPath & "\"
Else
Call ChooseMacFolder(strPath) 'if running on Mac, choose folder differently
End If
strFileName = strPath & "Company " & "- " & ReportDiv & " " & ReportMonth & " " & "2013" & ".pdf"
'...and export all report sheets to folder
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strFileName, _
IgnorePrintAreas:=False, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True
' IgnorePrintAreas:=False
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Title").Range("A23").Value = "" 'clear Div name from report title page
Sheets("Title").Range("A25").Value = Sheets("Dashboard").Range("G6") ' ...and set month back to last month
' Ungroup sheet selection
Sheets("TOC").Select
End Sub
After more research, I can see that the array of sheet names is assembled correctly, but the
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF
command only saves the last sheet name in the array. I can simulate the effect on Mac by manually selecting multiple sheets, then perform a File>Print>Save as PDF. This also only saves one of the selected sheets.
Anyone have any idea why the sheet array doesn't get saved correctly on Excel for Mac and if there might be a workaround so it does?
Bookmarks