Excel VBA - Copy and Rename File

af96

New Member
Joined
May 17, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

I am completely new to macros. I have seen many threads related to this topic, however, I have not been successful, so my apologies for duplicating a question.
I wish to create a macro which will open a template work book and save it as a specific file name. I have created a template file and another file with the custom names.

This is the thread that seems to have answered my query, but I was unsuccessful: Macro to Copy and Rename Files in Different Directory.

Please could anyone help?

Many thanks in advance.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
VBA Code:
Sub OneForAF96()
'Crafted by Wookiee at MrExcel.com

Dim wkbTemplate   As Workbook
Dim strNewFile    As String
Dim strSavePath   As String

'Open Template File
Workbooks.Open Filename:="X:\Path\YourTemplate.xlsx", ReadOnly:=True
Set wkbTemplate = ActiveWorkbook

'Assumes You Are Saving New File In Same Directory
'Change If You Want To Save Elsewhere
strSavePath = wkbTemplate.Path

'Get New Filename
strNewFile = InputBox("Enter new file name:")

wkbTemplate.SaveAs Filename:=strSavePath & "\" & strNewFile

End Sub
 
Upvote 0
Hello, thank you for this. Apologies for my silly question, but I'm not entirely sure what to put here:

strNewFile = InputBox("Enter new file name:")

As I need to pull this information from a separate sheet which lists the custom names.
 
Upvote 0
Hello, thank you for this. Apologies for my silly question, but I'm not entirely sure what to put here:

strNewFile = InputBox("Enter new file name:")

As I need to pull this information from a separate sheet which lists the custom names.
Apologies, that was meant as a place-holder where you could revise the macro logic to specify however you wanted to assign the file name.

Here's a rough example:

VBA Code:
strNewFile = Sheets("Separate Sheet").Range("A420").Value
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

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