Save File To Folder

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,060
Help would be appreciated.

I would like a script which would save my file named Xtemplate to a folder named C:\Temp\ExcelTemplates\

The only thing is I would like it if the script could add a new number to the file name if the file already exists in the destination folder.

I.e. Xtemplate already exists so save file as
Xtemplate1 (if Xtemplate1 exists, save as)
Xtemplate2 (if etc... etc....)
 
Thanks for your help Xenou and John.

I have used John's example and it works perfectly, greatly appreciated.:):):)
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi,

I am saving a new file to a new folder.

I'd like to have the folder be named as one of the cell, say A2.

Grateful for your help. :)
 
Upvote 0
ansariemacaurog, I need more details, like what is the file being saved, do you want to save the file in the new folder, is the folder name in A2 the full folder path including the new folder name or just the new folder name?

But at its simplest, suppose A2 on Sheet1 contains C:\temp\Excel\newFolder, the following code will create newFolder, but only if all preceding folders exist (C:\temp and C:\temp\Excel):
Code:
Sub CNF()
    If Dir(Sheets("Sheet1").Range("A2").Value, vbDirectory) = "" Then
        MkDir Sheets("Sheet1").Range("A2").Value
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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