SaveAs Unique Name

jaclynresendez

New Member
Joined
Jan 20, 2009
Messages
19
Hello All,

I'm trying to get my Command Button to save the workbook as a unique name each time. Here I have it saving with a specific filename and, if it already exists it's SUPPOSED to add a number to the name. Like if WorkbookA1 already exists then it's to save as WorkbookA2, THEN sends it in an email. The problem is it'll save the first book as filename1 but will not go on to save the next as filename2 if filename1 already exists. This is the code I already have:

Dim objFSO As Object
Dim i As Integer
Dim strFileNamePrefix As String
Dim strPath As String
Dim strUniqueFilename As String
strPath = "\\Snnp-oa-001\snnopertns\AutoRun\NGE_"
strFileNamePrefix = Range("B25")
Set objFSO = CreateObject("Scripting.FileSystemObject")
i = 1
While objFSO.FileExists(strPath & strFileNamePrefix & Pad(i, 3))
i = i + 1
Wend
Set objFSO = Nothing
strUniqueFilename = strPath & strFileNamePrefix & Pad(i, 3) & ".xls"
ActiveWorkbook.SaveAs strUniqueFilename
ActiveWorkbook.SendMail Recipients:=myemail@company.com

Any help or a better way to do this would be greatly appreciated. Was trying to get this done today, but may not. Hopefully it'll be ready to go tomorrow???
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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