VBA Rename Workbook is to rename workbook using Name As. Workbook represents an object. It is part of workbooks collection. We can rename active Workbook and can’t rename current Workbook. We can save as current workbook with another name. And then we can delete existing current file or Workbook. We can rename any file or workbook using Name As. The Current Workbook/file and New Workbook/file path should be same while renaming Workbook.
Here is the following syntax to Rename Workbook.
Name Old_Name As New_Name
Let us see the following example. It will rename Workbook .
'VBA ReName Workbook in Excel Sub VBA_ReName_Workbook() 'Variable declaration Dim sOldFile As String Dim sNewFile As String sOldFile = "D:\VBAF1\Old_File.xlsx" sNewFile = "D:\VBAF1\New_File.xlsx" Name sOldFile As sNewFile End Sub
Here are the instructions to use above macro procedure in Visual basic editor.
- Open Visual Basic Editor(VBE) by clicking Alt +F11
- Go to code window by clicking F7
- Copy above specified macro or procedure
- Paste above copied code in code window
- Run macro by clicking F5 or Run command
- You can see output on the screen
- Find above output screenshot of the specified procedure.
You may also like the related Workbook Object articles.