• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Save All Except 3 as xlsx in Active Folder with date (today)|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Save All Except 3 as xlsx in Active Folder with date (today)|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosSave All Except 3 as xlsx in Active…
sp_PrintTopic sp_TopicIcon
Save All Except 3 as xlsx in Active Folder with date (today)
Avatar
Sherry Fox
Poinciana, FL
Member
Members
Level 0
Forum Posts: 100
Member Since:
December 4, 2021
sp_UserOfflineSmall Offline
1
February 16, 2022 - 1:13 am
sp_Permalink sp_Print sp_EditHistory

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.

Sub SaveAuditFile()
' 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

sp_AnswersTopicSeeAnswer See Answer
Avatar
Sherry Fox
Poinciana, FL
Member
Members
Level 0
Forum Posts: 100
Member Since:
December 4, 2021
sp_UserOfflineSmall Offline
2
February 16, 2022 - 6:42 am
sp_Permalink sp_Print sp_EditHistory

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.

 

Sub SaveAuditFile()

' 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

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 689
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
3
February 22, 2022 - 7:57 pm
sp_Permalink sp_Print

I don't get any prompts with your code. You don't need two SaveAs lines though. The second one can just be:

wbkNew.Save

since you already saved the workbook in xlsx format.

sp_AnswersTopicAnswer
Answers Post
Avatar
Sherry Fox
Poinciana, FL
Member
Members
Level 0
Forum Posts: 100
Member Since:
December 4, 2021
sp_UserOfflineSmall Offline
4
February 25, 2022 - 2:18 am
sp_Permalink sp_Print

Thanks Velouria!

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 8
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
Hans Hallebeek: 185
Newest Members:
Appiagyei Kofi Frimpong
Hilary Burchfield
Richie Wright
Adel Kock
Barbara Murray
Doug Milne
Siobhan Stringer
Rob Rooth
Tom Lewis
Jennifer Rodriguez-Avila
Forum Stats:
Groups: 3
Forums: 24
Topics: 6542
Posts: 28641

 

Member Stats:
Guest Posters: 49
Members: 32829
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.