dynamic SaveAs w/ vb

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
is there a way to write code that will create a new file (i've got that), and save the new file as a specified file name - but, if that name already exists, will change the name (i.e. name, name1, name2, name3...) if it already exists?


i'm not having luck finding this in help resources.

oh, and one other :oops: (sorry about doubling up here)
i have code which will close the original book
Windows("Day_Report 4 Opacity 2003").Activate
ActiveWindow.Close
it always asks me if i want to save before closing (in lieu of changes, of course) and i never ever want to save. is there a way to bypass this?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
In response to your second thing

Activeworkbook.close false
will eliminate the prompt to save issue.

You might want to think about using the dir function to scan for the file save name in the default save folder prior to actually saving the file, if it finds the file name, then it increments a counter and check again?
 
Upvote 0
Cbrine,

that dir function sounds just what i need. thank you for taking the time to post a reply, this helps me greatly.
 
Upvote 0
FYI,
I used the dir function in MS access, and you need to put it in a loop and I think you look for !EOF. Just put your check vs the filename within the loop and exit the loop if you find a match, update your filename with the counter and run the loop again, until if get's through the entire loop. So place your save code after the Loop command. It has it own internal counter or something to keep track of the last file displayed. So each time it's executed it grabs the next file.
 
Upvote 0

Forum statistics

Threads
1,213,522
Messages
6,114,112
Members
448,549
Latest member
brianhfield

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top