December 4, 2021
I have a template (xlsb format), which I used Power Query to generate my data and that has 3 sheets that are standard, and then produces multiple (10-20) additional sheets, whose names vary each time time process is run. For audit purposes, I need to generate a copy with today's date. The copy must contain all sheets except the 3 standard. These sheets are in no particular order, and once the split generates the other sheets these sheets somehow appear to end up on opposite ends. The workbook should be saved in the SAME directory where the template is located (Active directory), with the same name and then the date added (Filename Example: Template Name - MM-DD-YYYY.xlsx). I also want to avoid that "nag" screen that appears when you manually save an xlsb as an xlsx file. Each Sheet Consists of Columns A - R, however the number of rows change from sheet to sheet and each time this task is performed. Currently, the Master, which is split, has over 50K+ rows of data. Note, we are forced to work off of OneDroive, and that messes up macros sometimes. If the file cannot automatically be saved to the Active Directory, I would like the user to be able to browse for the folder to save the file in. Thanks in advance!
- Master
- Status Percent
- codes (hidden sheet)
While I have been waiting to hear back, I was able to almost get my code to work. Everything works, except I get the "nag" screen stating that xlsx files cannot contain VBA. I want to avoid that. Other than that, everything I want appears to work just fine.
' Saves multiple sheets in another workbook based on the cell values
Dim wbkNew As Workbook ' NEW workbook
Dim wbkSrc As Workbook ' THIS workbook
Dim FName As String
Dim Path As String
' Optimize Macro Speed
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
' codes is Sheet3
FName = Sheet3.Range("$B$2") & " - " & Format(Now(), "DD-MMM-YYYY") & ".xlsx"
Path = ThisWorkbook.Path & "\" & FName
Set wbkSrc = ThisWorkbook
ActiveWorkbook.SaveAs Filename:=Path, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Set wbkNew = ActiveWorkbook
' Remove the extraneous sheets
wbkNew.Sheets("data").Delete
wbkNew.Sheets("QCH IMP Status Percent").Delete
wbkNew.Sheets("codes").Delete
ActiveWorkbook.SaveAs Filename:=Path, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
' ActiveWindow.Close <~~~ option to have the new workbook close
' AutoFit Every Worksheet Column in a Workbook
For Each sht In ThisWorkbook.Worksheets
sht.Cells.EntireColumn.AutoFit
Next sht
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
December 4, 2021
I was having a LOT of problems removing the attachments, forgive the active edit history. Attached is the revised book with my updated code. I am very close. At this point, I only need the file to save WITHOUT the nag screen that advises xlsx files cannot contain VBA. That portion should be seamless. Thanks.
' Saves multiple sheets in another workbook based on the cell values
Dim wbkNew As Workbook ' NEW workbook
Dim wbkSrc As Workbook ' THIS workbook
Dim FName As String
Dim Path As String
' Optimize Macro Speed
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
' codes is Sheet3
FName = Sheet3.Range("$B$2") & " - " & Format(Now(), "DD-MMM-YYYY") & ".xlsx"
Path = ThisWorkbook.Path & "\" & FName
Set wbkSrc = ThisWorkbook
ActiveWorkbook.SaveAs Filename:=Path, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Set wbkNew = ActiveWorkbook
' Remove the extraneous sheets
wbkNew.Sheets("data").Delete
wbkNew.Sheets("QCH IMP Status Percent").Delete
wbkNew.Sheets("codes").Delete
ActiveWorkbook.SaveAs Filename:=Path, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
' ActiveWindow.Close <~~~ option to have the new workbook close
' AutoFit Every Worksheet Column in a Workbook
For Each sht In ThisWorkbook.Worksheets
sht.Cells.EntireColumn.AutoFit
Next sht
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
1 Guest(s)