Rename active workbook

John

New Member
Joined
Mar 12, 2002
Messages
24
I need to rename a workbook without saving it. Is there any way of doing this in VBA, or any other way?
Thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
On 2002-03-20 21:08, John wrote:
I need to rename a workbook without saving it. Is there any way of doing this in VBA, or any other way?
Thanks

Try this (and yes, to rename you have to save...otherwise there will be nothing there. If you still want your old copy, then don't use the Kill line).

ActiveWorkbook.SaveAs "MyFile.xls"
Kill "MyPreviousFileName.xls"

Hope this helps,

Russell
 
Upvote 0
What can you do if the file you want to delete varies in names?

My file name will depend on what it was saved as originally, and this is pulled from a cell.
 
Upvote 0
this is what I have so far that isn't working, looking at what you provided and amending it with some information I got from elsewhere -


ActiveWorkbook.SaveAs "S:\aliclock\Department Forms\Delete\Sickness Forms Complete.xlsm"
Kill "S:\aliclock\PAULINE SICKNESS TEST\" & Range("b11").Value
Application.Quit

It still is erroring, any ideas?
 
Upvote 0
Try this one ......

WBname$ = ThisWorkbook.FullName
NewWBname$ = Left(WBname$, Len(WBname$) - 4) ' remove .xls
NewWBname$ = NewWBname$ & "SMALL.xls"
ActiveWorkbook.SaveAs NewWBname$
Kill WBname$


Prompt$ = "Now Saved as a SMALL file at " & NewWBname$ & Chr(13)
Prompt$ = Prompt$ & " Killed " & WBname$ & Chr(13)
Prompt$ = Prompt$ & " DONE "
MsgBox Prompt$
 
Upvote 0
I was in a similar situation. I.E. I wanted to open up a copy of a template workbook, but name it specifically to the instance. You can save it as a temp file in your default %TEMP% folder. .tmp files are deleted on close. Therefore, it renames the file without saving another copy.

Dim wb As Excel.Workbook
Set wb = xApp.Workbooks.Add("S:\Engineering\Test_Sample_DB_files\SampleData.xltx")
wb.SaveAs "C:\Users\sshive\AppData\Local\Temp\" & CStr(id) & ".tmp"
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,913
Members
448,532
Latest member
9Kimo3

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