Trying to save as 'filename'

viggie79

New Member
Joined
Dec 10, 2015
Messages
14
Hello, I'm having trouble with what should be a very easy excel problem.

I am opening a file from my desktop and running it through a macro. I then need to save it to a specific folder and would like the macro to do this for me.
I tried just recording a macro:
Code:
 ActiveWorkbook.SaveAs Filename:= _
"C:\Users\rr235108\Desktop\xmacrostuffx\Export_12-18-15.xls", _
FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
The name of this file is "Export_12-18-15" but each day it will be a different file name: export_12-19-15, export_12-20-15 etc. but this macro will save every file as "export_12-18-15.xls", correct? How do I work around this?
 

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
3,963
try
Code:
Sub savename()
    ActiveWorkbook.SaveAs Filename:= _
"C:\Users\rr235108\Desktop\xmacrostuffx\Export_" & Format(Date, "mm-dd-yy") & ".xls", _
FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
 

viggie79

New Member
Joined
Dec 10, 2015
Messages
14
This works great for my problem, thank you so much! What if my filename was something that I couldn't fix up using the Date format, like 'Day1File', 'Day2File', 'Day3File' etc.? There must be a simple way to just save as the current filename. For example, when I save as by clicking manually, the filename field above the file type is populated automatically with the current name of the file. How can I replicate that in a macro?
 

viggie79

New Member
Joined
Dec 10, 2015
Messages
14
I found what I was looking for here Save as File with Same File Name | Chandoo.org Excel Forums - Become Awesome in Excel
For anyone else looking for the same thing I was; ActiveWorkbook.Name works as a variable in this case.
Final product would look something like this
Code:
ActiveWorkbook.SaveAs Filename:= _        "C:\folder\location\path\" & ActiveWorkbook.Name, FileFormat:=xlExcel8, _
        Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
        CreateBackup:=False
 

Forum statistics

Threads
1,082,280
Messages
5,364,214
Members
400,786
Latest member
ismi88

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top