ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   variables for file names (https://www.excelbanter.com/excel-programming/271234-variables-file-names.html)

mike

variables for file names
 
I prompt a user to select the file they want. They do
this for three different files. I would like to create a
variable with the file name only. That way, later in the
program, I would like to refer to the appropriate workbook
based on the file name they selected.

For instance, I would like to do something like this:

Workbooks (vFileName1).Activate or
Workbooks (vFileName2).Close

The variables I have created so far also contain the
path. My variable looks like this:
Workbooks (C:\MyDocs\File1.xls)

Is it possible to create a variable with only the file
name and not the entire path? Thanks for the help.

Henry[_4_]

variables for file names
 
Mike,

Dim Mypath, Myfile as String

Mypath ="C:\MyDocs\"
Myfile ="File1.xls"

Workbooks (Mypath & Myfile).Activate or
Workbooks (Mypath & Myfile).Close

HTH
Henry

"mike" wrote in message
...
I prompt a user to select the file they want. They do
this for three different files. I would like to create a
variable with the file name only. That way, later in the
program, I would like to refer to the appropriate workbook
based on the file name they selected.

For instance, I would like to do something like this:

Workbooks (vFileName1).Activate or
Workbooks (vFileName2).Close

The variables I have created so far also contain the
path. My variable looks like this:
Workbooks (C:\MyDocs\File1.xls)

Is it possible to create a variable with only the file
name and not the entire path? Thanks for the help.





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

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