Eindhoven_Excel
New Member
- Joined
- Feb 5, 2021
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hi All,
I am using at the moment a VBA code to create a new workbook. It´s financial data and therefore I want to use the group function to show detail in my totals. Next, i want to protect the two newly created sheets and save it as a new workbook. So everything works fine till this point, but after opening the saved file the group function is not available as it is a protected sheet.
Is there a way to create a VBA code that generates a new workbook from a masterfile and saves the workbook as a protected file where you can still use the group/ungroup function? The problem is now that te current code only works till you open a file.
I was thinking of a VBA code that runs everytime you open the saved workbook, but how can you type this in another vba code? So how can you generate a VBA code for a new VBA enabled file.
I am using at the moment a VBA code to create a new workbook. It´s financial data and therefore I want to use the group function to show detail in my totals. Next, i want to protect the two newly created sheets and save it as a new workbook. So everything works fine till this point, but after opening the saved file the group function is not available as it is a protected sheet.
Is there a way to create a VBA code that generates a new workbook from a masterfile and saves the workbook as a protected file where you can still use the group/ungroup function? The problem is now that te current code only works till you open a file.
I was thinking of a VBA code that runs everytime you open the saved workbook, but how can you type this in another vba code? So how can you generate a VBA code for a new VBA enabled file.
VBA Code:
Sub VestigingOpslaan()
Dim FileName As String
Dim Path As String
Application.Calculation = xlCalculationManual
With ThisWorkbook
.Worksheets("XXX").Copy
ActiveSheet.Cells.Copy
ActiveSheet.Range("A1").PasteSpecial Paste:=xlValues
.Worksheets("XXXX").Copy After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
ActiveSheet.Cells.Copy
ActiveSheet.Range("A1").PasteSpecial Paste:=xlValues
Application.DisplayAlerts = False
ActiveSheet.Protect Password:="XXX", UserInterfaceOnly:=True
ActiveSheet.EnableOutlining = True
Path = "H:\Documenten\"
FileName = Range("E2").Value & " " & Range("P6").Value & ".xlsm"
ActiveWorkbook.SaveAs Path & FileName, xlOpenXMLWorkbookMacroEnabled
Application.DisplayAlerts = True
End With
Application.CutCopyMode = False
Application.Calculation = xlCalculationAutomatic
End Sub