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.
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,066
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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
 

M0J0jojo

New Member
Joined
Nov 27, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
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 :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,454
Messages
5,596,228
Members
414,047
Latest member
debbos

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
Top