Background:
I have a file containing sensitive information. I process that information and assign each row to different units, where some information goes to several units. Everything is compiled in a pivot table, and then I have a macro that goes through several different cycles of "Show report filter pages", so in the end I end up with around a 100 worksheets, each containing a pivot table with only the information that particular unit should receive. Then I run a VBA-script, that I have no idea who wrote in the first place, but copies and versions of it can be found in every forum on the internet in how to save each worksheet as a separate file.
I started doing this when my organisation had Excel 2010, and all worked extremely well. A colleague of mine took over this routine. We then changed version, and now run Excel 2019, and this was when he encountered some problems. The whole procedure all of a sudden took ages to run. He has now adapted to this and just start it at the end of the day, and let it run for an hour or so. I just looked at it and noticed that the new files are huge. When using Excel 2010 the new saved files were 50-200 kB, but now they are about 5000 kB. If I open the file, it looks like it only contains one sheet and everything is only values, but if I change the file extension to .zip, and unpack and look at the metadata I can see that all the data that make up the original pivot table is hidden in each file. This creates two major problems; the files are so big that they overcrowd the mailboxes, and the worst thing is that we actually mail sensitive information that is not supposed to be shared to each recipient.
I have no idea why Excel save the files differently between 2010 and 2019. Some help on how to get around this would be much appreciated.
This is tha VBA script I use (thank you original creator).
I have a file containing sensitive information. I process that information and assign each row to different units, where some information goes to several units. Everything is compiled in a pivot table, and then I have a macro that goes through several different cycles of "Show report filter pages", so in the end I end up with around a 100 worksheets, each containing a pivot table with only the information that particular unit should receive. Then I run a VBA-script, that I have no idea who wrote in the first place, but copies and versions of it can be found in every forum on the internet in how to save each worksheet as a separate file.
I started doing this when my organisation had Excel 2010, and all worked extremely well. A colleague of mine took over this routine. We then changed version, and now run Excel 2019, and this was when he encountered some problems. The whole procedure all of a sudden took ages to run. He has now adapted to this and just start it at the end of the day, and let it run for an hour or so. I just looked at it and noticed that the new files are huge. When using Excel 2010 the new saved files were 50-200 kB, but now they are about 5000 kB. If I open the file, it looks like it only contains one sheet and everything is only values, but if I change the file extension to .zip, and unpack and look at the metadata I can see that all the data that make up the original pivot table is hidden in each file. This creates two major problems; the files are so big that they overcrowd the mailboxes, and the worst thing is that we actually mail sensitive information that is not supposed to be shared to each recipient.
I have no idea why Excel save the files differently between 2010 and 2019. Some help on how to get around this would be much appreciated.
This is tha VBA script I use (thank you original creator).
VBA Code:
Sub Copy_Every_Sheet_To_New_Workbook()
Application.ScreenUpdating = False
'Working in 97-2010
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
'Copy every sheet from the workbook with this macro
Set Sourcewb = ThisWorkbook
'Create new folder to save the new files in
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = Sourcewb.Path & "\" & Sourcewb.Name & " " & DateString
MkDir FolderName
'Copy every visible sheet to a new workbook
For Each sh In Sourcewb.Worksheets
'If the sheet is visible then copy it to a new workbook
If sh.Visible = -1 Then
sh.Copy
'Set Destwb to the new workbook
Set Destwb = ActiveWorkbook
'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2010
If Sourcewb.Name = .Name Then
MsgBox "Your answer is NO in the security dialog"
GoTo GoToNextSheet
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With
'Change all cells in the worksheet to values if you want
If Destwb.Sheets(1).ProtectContents = False Then
With Destwb.Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False
End If
'Save the new workbook and close it
With Destwb
.SaveAs FolderName & "\" & Destwb.Sheets(1).Name & FileExtStr, FileFormat:=FileFormatNum
.Close False
End With
End If
GoToNextSheet:
Next sh
MsgBox "You find your files in " & FolderName
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
Application.ScreenUpdating = True
MsgBox "Files are created"
End Sub