Hi
I run the SaveShtsAsBook macro below to separate a worksheets into individual workbooks in order to send reports to multiple customers. My problem is that I generate the worksheets from a pivot table filtered by customer reference number. It has occurred to me that even after separating the worksheets the pivot table filters are still 'live'
In order to keep confidentiality I need to do one of two things:
Lock the pages and keep them locked after running SaveShtsAsBook
Or get the macro to lock the workbooks when I run SaveShtsAsBook
I've tried locking all pages and then running SaveShtsAsBook but the individual workbooks are unlocked after macro is run defeating the process. I'm no tech wizard and just found this on the internet but it works fine except the filters still showing.
This is my macro:
Sub SaveShtsAsBook()
Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
MyFilePath$ = ActiveWorkbook.Path & "\" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' End With
On Error Resume Next '<< a folder exists
MkDir MyFilePath '<< create a folder
For N = 1 To Sheets.Count
Sheets(N).Activate
SheetName = ActiveSheet.Name
Cells.Copy
Workbooks.Add (xlWBATWorksheet)
With ActiveWorkbook
With .ActiveSheet
.Paste
.Name = SheetName
[A1].Select
End With
'save book in this folder
.SaveAs FileName:=MyFilePath _
& "\" & SheetName & ".xlsx"
.Close SaveChanges:=True
End With
.CutCopyMode = False
Next
End With
Sheet1.Activate
End Sub
I run the SaveShtsAsBook macro below to separate a worksheets into individual workbooks in order to send reports to multiple customers. My problem is that I generate the worksheets from a pivot table filtered by customer reference number. It has occurred to me that even after separating the worksheets the pivot table filters are still 'live'
In order to keep confidentiality I need to do one of two things:
Lock the pages and keep them locked after running SaveShtsAsBook
Or get the macro to lock the workbooks when I run SaveShtsAsBook
I've tried locking all pages and then running SaveShtsAsBook but the individual workbooks are unlocked after macro is run defeating the process. I'm no tech wizard and just found this on the internet but it works fine except the filters still showing.
This is my macro:
Sub SaveShtsAsBook()
Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
MyFilePath$ = ActiveWorkbook.Path & "\" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)
With Application
.ScreenUpdating = False
.DisplayAlerts = False
' End With
On Error Resume Next '<< a folder exists
MkDir MyFilePath '<< create a folder
For N = 1 To Sheets.Count
Sheets(N).Activate
SheetName = ActiveSheet.Name
Cells.Copy
Workbooks.Add (xlWBATWorksheet)
With ActiveWorkbook
With .ActiveSheet
.Paste
.Name = SheetName
[A1].Select
End With
'save book in this folder
.SaveAs FileName:=MyFilePath _
& "\" & SheetName & ".xlsx"
.Close SaveChanges:=True
End With
.CutCopyMode = False
Next
End With
Sheet1.Activate
End Sub