I would like to code in vba to automatically file save the workbook using the name in a certain cell. Say if cell, A1 has the value of CD-0001, that is what the filename I would like to be saved. I also want to use the same directory in which the current workbook was opened from. A1 is formula driven and will change each time the workbook is opened. I am very new to VBA and have used the macro recorder to record my actions doing the above, but now can not figure out how to make it “dynamic” to always use the name in cell A1 and use the same directory which stored the original workbook when opened. My intention is to only use the macro for the first time to save the workbook, but what happens when I run the macro and it has already been saved? Is there a way to trap for this or have the file save without prompting the usual over write message input box? I am so new to this process, is there something else I should consider in this macro? It seemed like this was going to be fairly straight forward when I started this process this morning. THANKS.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Dynamic File Save as (EXCEL 97, Win 98)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Dynamic File Save as (EXCEL 97, Win 98)
- This topic has 3 replies, 3 voices, and was last updated 22 years, 1 month ago.
AuthorTopicJimmyc5559
AskWoody PlusMarch 28, 2003 at 7:54 pm #385432Viewing 0 reply threadsAuthorReplies-
H. Legare Coleman
AskWoody PlusMarch 28, 2003 at 8:26 pm #664831There are two additional questions that you need to answer before this can be completed. What do you want the macro to do if this is a new workbook that has never been saved, and therefore there is no path to the directory. What do you want the macro to do if cell A1 is empty, and therefore there is no file name?
The following macro needs to have those filled in:
Public Sub WBSave() If Worksheets("Sheet1").Range("A1").Value = "" Then ' Cell A1 is empty, what do you want to do now? Exit Sub End If If ActiveWorkbook.Path = "" Then ' The workbook has never been saved, what do you want to do here? Exit Sub End If Application.DisplayAlerts = False ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "" & Worksheets("Sheet1").Range("A1").Value Application.DisplayAlerts = True End Sub
-
Jimmyc5559
AskWoody PlusMarch 28, 2003 at 10:05 pm #664859Since the initial workbook opened was my “master” work book, I want to use the same path to save the “dynamic” filename that was used to open the “master” workbook. For example, if the “master” workbook is contained in ” c:mydocumentsexcel ” , I would want to save the excel file to the same directory with the “dynamic” name. I didn’t want to “overwrite” the “master” excel workbook. The other question is more difficult as I obviously made the assumption that I or the person working with me will NEVER erase the formula is cell A1—thus having it blank when the “filesave” macro is executed. I guess I could “protect” the cell and I’m really struggling with other alternatives. One alternative my be is if the cell is blank, the macro could stop execution and display a text box. To be honest, if the formula in A1 is inadvertently erased, the current excel file should just be close without saving and the “master” workbook re-open as I’m using a counter in cell A1. Thanks for your patience with a newbie like me–its appreciated.
-
WSJohnBF
AskWoody LoungerMarch 28, 2003 at 10:25 pm #664861Although, as Legare notes elsewhere, Excel is not highly secure, you could place data called only by the code, such as your proposed workbook name and counter, in unprotected cells in a password-locked hidden worksheet in the master WB. That way any overwriting of data you don’t wish modified has to be done very deliberately.
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
34 minutes ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
36 minutes ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
3 hours, 46 minutes ago -
Out of band for Windows 10
by
Susan Bradley
5 hours, 19 minutes ago -
Giving UniGetUi a test run.
by
RetiredGeek
12 hours, 16 minutes ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
19 hours, 53 minutes ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
17 hours, 52 minutes ago -
Auto Time Zone Adjustment
by
wadeer
1 day ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
22 hours, 3 minutes ago -
Manage your browsing experience with Edge
by
Mary Branscombe
2 hours, 38 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
13 hours, 34 minutes ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
17 hours, 51 minutes ago -
Apps included with macOS
by
Will Fastie
17 hours, 29 minutes ago -
Xfinity home internet
by
MrJimPhelps
17 hours, 24 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
17 hours, 22 minutes ago -
Debian 12.11 released
by
Alex5723
1 day, 21 hours ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
2 days, 1 hour ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
1 day, 4 hours ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
21 hours, 3 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
2 days, 18 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
2 days, 8 hours ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
6 hours, 15 minutes ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
2 days, 13 hours ago -
Some advice for managing my wireless internet gateway
by
LHiggins
1 day, 20 hours ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
22 hours, 34 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
3 days, 6 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
18 hours, 23 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
2 days, 16 hours ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
3 days, 20 hours ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
2 days, 4 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.