I am using the following code in order to export a macro enabled report to an .xls file with only certain worksheets from the original workbook.
Sub exportFile()
Dim sh As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
dates = Format(Now, "dd-mm-yyyy")
CurrentWorkbookName = ActiveWorkbook.Name
NewWorkbookName = "Friday Commentary " & dates & ".xlsx"
filePath = ActiveWorkbook.Path
Set NewBook = Workbooks.Add
With NewBook
.Title = "All Sales"
.Subject = "Sales"
.SaveAs Filename:=filePath & "\" & NewWorkbookName ', FileFormat:=50 '50 = xlExcel12 (Excel Binary Workbook in 2007-2013 with or without macro's, xlsb)
End With
Workbooks(CurrentWorkbookName).Activate
For Each sh In Worksheets
If sh.Name = "1" Or sh.Name = "2" Or sh.Name = "3" Or sh.Name = "4" Or sh.Name = "5" Or sh.Name = "6" Or sh.Name = "EXPORT" Or sh.Name = "RAW" Then
Workbooks(CurrentWorkbookName).Sheets(sh.Name).Copy After:=Workbooks(NewWorkbookName).Sheets(Workbooks(NewWorkbookName).Sheets.Count)
Workbooks(CurrentWorkbookName).Activate
End If
Next
End Sub
Each sheet from 1 - 6 has a pivot table from the same data source. I want these pivot tables to be only extracted as values (not a pivot table) with the pivot table formatting, of course. How do I include this in my macro?
sh.UsedRange.Value = sh.UsedRange.Value
will work, or substituteUsedRange
for a more defined range. – Scott Holtzman