ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cell reference to determine filename (https://www.excelbanter.com/excel-programming/429431-cell-reference-determine-filename.html)

cangiff

Cell reference to determine filename
 
I am trying to write a macro that saves a current file to a new file.

in the VBA line: ActiveWorkbook.SaveAs Filename =

I want to add a reference to the cell that contains the required filename. I
have therefore tried adding the following:

ActiveWorkbook.SaveAs Filename = "=' [macro test.xls] Sheet 1' !R10C3"

This address contains the desired filename. However when I run the macro it
fails as "the file could not be accessed......."

I suspect my programmming is flawed. Can you help?

Actiallows me to put the required filename that I wish to save to in as a
--
cangiff

cangiff

Cell reference to determine filename
 
Thank you that works perfectly
--
cangiff


"Jacob Skaria" wrote:

Try the below

Dim strFile as String
strFile = Workbooks("macro test.xls").Sheets("Sheet1").Range("C10")

OR
'if this is the active workbook
strFile = Sheets("Sheet1").Range("C10")

ActiveWorkbook.SaveAs Filename:=strFile
--
If this post helps click Yes
---------------
Jacob Skaria


"cangiff" wrote:

I am trying to write a macro that saves a current file to a new file.

in the VBA line: ActiveWorkbook.SaveAs Filename =

I want to add a reference to the cell that contains the required filename. I
have therefore tried adding the following:

ActiveWorkbook.SaveAs Filename = "=' [macro test.xls] Sheet 1' !R10C3"

This address contains the desired filename. However when I run the macro it
fails as "the file could not be accessed......."

I suspect my programmming is flawed. Can you help?

Actiallows me to put the required filename that I wish to save to in as a
--
cangiff



All times are GMT +1. The time now is 04:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com