Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro to name file 3

Status
Not open for further replies.

tdonahue

Technical User
Feb 4, 2001
50
0
0
US
I could use a macro to automatically name a file, which a person would enter in a message box and the current date.

 
Hi Psalm6229,

A bit more info please! What sort of File? Do you want to rename an existing file, or create a copy of one, or save a new file? Is the file you want to name, open? Which application are you using?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
I have an existing blank excel file that has ten sheets in it. The users get the files mixed up so I want a macro that names the excel file the name of the existing file "proforma" and adds the current date to the end of the name proforma. Example proforma0301. I also want the excel file to remain in a default directory, named C:\Excel Files
 
Take a look at the Format function:
? Format(Date, "mmdd")
0302

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi Psalm6229,

I'm still unclear as to what you want to do, but maybe this will help. To save the current Workbook in Excel with a name based on User input, you could do this ..

Code:
[blue]myname = InputBox("Name?")
ActiveWorkbook.SaveAs "C:\Excel Files\" & myname & Format(Date, "mmdd") & ".xls"[/blue]

Alternatively, to base the name on the existing workbook name you could do this ..

[blue]
Code:
p = InStr(ActiveWorkbook.Name, ".")
If p = 0 Then
    myname = ActiveWorkbook.Name
Else
    myname = Left(ActiveWorkbook.Name, p - 1)
End If
ActiveWorkbook.SaveAs "C:\Windows\Desktop\" & myname & Format(Date, "mmdd") & ".xls"
[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Tony,

I think this is what I need. I will try this tonight and see if it works for me.
 
Tony,

I tried both sets of code. I guess what I really want is the first code without the input box, because I know the name of the file, which is proforma. Do you have any sugestions?

Tom
 
Try this:
ActiveWorkbook.SaveAs "C:\Excel Files\Proforma" & Format(Date, "mmdd") & ".xls"


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks Tony and PHV !!! I tried the last suggestion by PHV and it works great !!! It is exactly what I need !!


Tom
 
Hello

I also have a rename file question.
I have a spreadsheet that reads external text files in VBA to populate my spreadsheet. As part of the process I want to rename those external text files after I have read their data.

Can I do this?

Thanks for your time.

Regards
Chris Bezant
 
Hi Chris,

To rename a file:
Code:
[blue]Name "C:\Path\To\File.txt" As "C:\Path\To\NewName.txt"[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top