ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Using cell value in filenames (https://www.excelbanter.com/excel-worksheet-functions/99924-using-cell-value-filenames.html)

Neil Beddell

Using cell value in filenames
 
Is it possible to use a cell value (a text value) in a filename? Have tried
to set the value of the a variable to cell value than incorporate that into
the saveas method but to no avail. Any help appreciated.


Neil Beddell

vezerid

Using cell value in filenames
 
Neil,
the following code fragment should work:

ThisWorkbook.SaveAs Filename:=Range("A1")

Otherwise post the code you are using. What kind of error are you
getting?

HTH
Kostis Vezerides


Neil Beddell

Using cell value in filenames
 
Kostis,

Many thanks for that line. All now works fine and I managed to incorporate
the file path into the code also. I was trying to set a variable to the
relevant range and incorporate that into the saveas code but I suspect that I
did not declare the variable correctly or was using an overly complex line of
code to set the variable value. I'm more used to working in access. Thanks
for your help.


NB

"vezerid" wrote:

Neil,
the following code fragment should work:

ThisWorkbook.SaveAs Filename:=Range("A1")

Otherwise post the code you are using. What kind of error are you
getting?

HTH
Kostis Vezerides



vezerid

Using cell value in filenames
 
Neil,

thanks for the feedback. Let me clarify some things further:

The Filename:=x
expects a string for x. The assignment made here is actually

Filename:=Range("A1").Value

Value is the default property of the Range object that it could be
omitted. The expression Range("A1") refers to an object, which is not
the proper data type for this assignment. If you wanted to assign
Range("A1") to an object variable you would need

Dim rng as Object 'or Dim rng as Range
Set rng = Range("A1")

Access VBA works in the same manner re objects and simple data types.
The online documentation clarifies these things. WHen in the VBA IDE
just click on the work SaveAs and press F1. From there you will start
seeing how the object libraries work.

HTH
Kostis



All times are GMT +1. The time now is 11:46 PM.

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