VBA Save As New Name

Gian624

Board Regular
Joined
Jul 23, 2009
Messages
92
Hi Everyone,

I have a macro I run that opens the files in a folder, runs a macro to update the file and saves it (Save As) to another folder. What I want to do now is have the last 10 characters on the file name removed and replaced with 10 characters on the spreadsheet.

The last part of the code says:

ActiveWorkbook.SaveAs Filename:=Location & myFile & ".xlsm"
wb.Close

Location is the folder I am saving to and myFile is the name of the file. Id like to automatically rename myFile with the last 10 characters off and replaced with the contents in range("B13").

Thanks,
Matt
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Untested and no error handling in the event that my file contains less than 10 characters.
Code:
ActiveWorkbook.SaveAs Filename:=Location & Left(myFile,Len(myFile)-10 & [B13] & ".xlsm"
 
Upvote 0
Thanks Joe,

I changed the -10 to -15 because I forgot to take out the .xlsm. Also, I Dim'ed another string for B13 and replaced it with what was in the range on the sheet. Other then that it worked great.

Thanks,
Matt
 
Upvote 0
Thanks Joe,

I changed the -10 to -15 because I forgot to take out the .xlsm. Also, I Dim'ed another string for B13 and replaced it with what was in the range on the sheet. Other then that it worked great.

Thanks,
Matt
You are welcome - thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,003
Members
448,935
Latest member
ijat

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