filename in macro

Y

ynissel

whats the syntax to save a file in a macro but use the file from within a cell
i.e. if cell A1 is the name I want to save the file as - how do I reference
that cell from within the macro?
 
M

MartinShort

Try this:


Code
-------------------
Sub saveFile()
Dim myPath As String
Dim myfileName As String
myPath = "C:\"
myfileName = myPath & Range("A1")
ActiveWorkbook.SaveAs Filename:=myfileName
End Su
-------------------


Change the variable pathName to suit your needs.

HTH

Marti
 
B

Bob Phillips

Activeworkbook.SAveAs Filename = Worksheets("Sheet1").Range("A1")

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
G

Gary''s Student

Let's put qwerty.xls in cell A1. Then:

Sub Macro1()
ChDir "C:\"
ActiveWorkbook.SaveAs Filename:="C:\" & Cells(1, 1).Value
End Sub

will do a save_as to your top-level directory.
 
Y

ynissel

this is great - thanks! what would the syntax be if the range I want to name
is in a sheet called backup and the cell is A15?
Thanks again.
 
B

Bob Phillips

Activeworkbook.SAveAs Filename = Worksheets("backup").Range("A15")


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
Y

ynissel

What am I doing wrong?
my macro reads:
ChDir "S:\Underwriting\Secondary\Wholesale\WS Rate Sheets"
ActiveWorkbook.SaveAs Filename = Worksheets("Rate Sheet Backup").Range("A31")

Cell A31 reads:
="AFC Wholesale Rate Sheet
"&MONTH(TODAY())&"-"&DAY(TODAY())&"-"&YEAR(TODAY())

and Im getting a file name of false? when the macro runs.
Thanks again,
Yosef
 
B

Bob Phillips

ChDir "S:\Underwriting\Secondary\Wholesale\WS Rate Sheets"
ActiveWorkbook.SaveAs Filename:=Worksheets("Rate Sheet Backup").Range("A31")

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
Top