Using a cell reference in a filepath

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

The following code saves the active workbook in c:/files

ActiveWorkbook.SaveAs "C:\files\" & ActiveWorkbook.Name

However, I have two sub folders in c:\files,

c:\files\new\ and c:\files\old\

Is it possible to add a cell reference to the end of

ActiveWorkbook.SaveAs "C:\files\"

so I can type, for example, "old" or "new" in cell A1, and when I save using
the above code, excel will save in the appropriate sub folder?

I have tried along the lines of:

ActiveWorkbook.SaveAs "C:\files\Range("A1")" & ActiveWorkbook.Name

but I cannot get it to work.

Thanks in advance.

Pinda.
 
Close !

ActiveWorkbook.SaveAs "C:\files\Range" & Range("A1").Value &
ActiveWorkbook.Name


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
The code you entered was almost right, this should work

ActiveWorkbook.SaveAs "C:\files\" & Range("A1") & "\" &
ActiveWorkbook.Name
 
Bob,

Thanks again for the help, but the code you've given does not save the file
in the subfolder (old), it just adds "rangeold" to the front of the filename
and saves it in c:\files.


So if the file is called test.xls, it will now be called rangeoldtest.xls.

I want the file to be saved in the subfolder "old" if cell A1 contains the
text "old", or the file to be saved in the subfolder "new" if cell A1
contains the text "new"


Thanks again,

Pinda.
 
Sorry, I wasn't careful enough, didn't see you hade the Range as well

ActiveWorkbook.SaveAs "C:\files\" & Range("A1").Value & "\" & _
ActiveWorkbook.Name

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Bob/Sean,

Bob u the man, thanks, I'm learning slowly but surely!

Thanks to Sean as wel,

In a bit,

Pinda
 

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

Back
Top