Save As Macro

I

iperlovsky

I am running the following sub routine, but I would like the new file name to
incorporate a specific cell value so that the file will always be saved in
the most current folder.

Sub SaveAs()
ActiveWorkbook.SaveAs Filename:="N:\FOLDER1\MyFile.xls"
End Sub

For example, in the modified code below I would like folders {yyyy} and
{mm-yyyy} to reference cells A2 and A3, respectively, in a specific worksheet
in the active workbook.

ActiveWorkbook.SaveAs Filename:="N:\FOLDER1\{yyyy}\{mm-yyyy}\MyFile.xls"

Thanks for the help,

IP
 
M

Mike H

Hi,

SaveAs is an illegal sub name. Try this for your saveas line

ActiveWorkbook.SaveAs Filename:="N:\FOLDER1\" & Range("A2").Value &
Range("A3").Value & "\MyFile.xls"

Mike
 
M

Mike

yyyy = Range("A2").Value
mmyyyy = Range("A3").Value
ActiveWorkbook.SaveAs Filename:="C:\FOLDER1\" & yyyy & "\" & mmyyyy &
"\MyFile.xls"
 
I

iperlovsky

Range("A2") is a date and I want to use just the year from it for yyyy. I
tried this Text(Year(Range("B6").Value), "0000") but received an error.

Also, Range("A3") is a date which I want to be month-year for mmyyyy. I
tried this Text(Range("B6").Value), "mm-yyyy") but received an error.

any suggestions?
 
J

Justin Larson

My first attempt at a simple VBA action. This post made it possible. Was
trying to figure out how to save as based on the value in a cell, and this
did the trick.

Thanks a ton.

-Liver
 
M

Mike

Sub doit()
yyyy = Format(Range("A2").Value, "yyyy")
mmyyyy = Format(Range("A3").Value, "mm-yyyy")
ActiveWorkbook.SaveAs Filename:="C:\FOLDER1\" & yyyy & "\" & mmyyyy &
"\MyFile.xls"
End Sub
 
P

Per Jessen

Try this:

MyYear = Year(Range("A2").Value)
mmYY = Format((Range("A3").Value), "mm-yyyy")
MySaveAsFileName = "N:\FOLDER1\" & MyYear & "\" & mmYY & "\MyFile.xls"
ActiveWorkbook.SaveAs Filename:=MySaveAsFileName

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top