Rename a file using cell contents with VBA

M0J0jojo

New Member
Joined
Nov 27, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

New here and a VBA newb too, I'm tearing my hair out on something that I'm sure has a simple solution.

I'm trying to create a macro to rename a (closed) file in a specific directory and I want to rename it with the contents of a cell in my active workbook.
I've been trying to use the Name and As method.

So I have something like this

VBA Code:
Name "C:\Documents\Sample file 1.xlsm" As "C:\Documents\Sample file 2.xlsm"

I just want to rename the file from Sample file 1.xlsm to the contents of Cell A2 on the active workbook.

Any help would be hugely appreciated.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi All,

New here and a VBA newb too, I'm tearing my hair out on something that I'm sure has a simple solution.

I'm trying to create a macro to rename a (closed) file in a specific directory and I want to rename it with the contents of a cell in my active workbook.
I've been trying to use the Name and As method.

So I have something like this

VBA Code:
Name "C:\Documents\Sample file 1.xlsm" As "C:\Documents\Sample file 2.xlsm"

I just want to rename the file from Sample file 1.xlsm to the contents of Cell A2 on the active workbook.

Any help would be hugely appreciated.
Something like this
VBA Code:
Name "C:\Documents\Sample file 1.xlsm" As "C:\Documents\" & ActiveCell.Value & ".xlsm"

'If the name has the extension in cell A2
Name "C:\Documents\Sample file 1.xlsm" As "C:\Documents\" & ActiveCell.Value
 
Upvote 0
Something like this
VBA Code:
Name "C:\Documents\Sample file 1.xlsm" As "C:\Documents\" & ActiveCell.Value & ".xlsm"

'If the name has the extension in cell A2
Name "C:\Documents\Sample file 1.xlsm" As "C:\Documents\" & ActiveCell.Value
This worked perfectly, thank you so much :)
 
Upvote 0

Forum statistics

Threads
1,214,567
Messages
6,120,268
Members
448,953
Latest member
Dutchie_1

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