View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Henry[_4_] Henry[_4_] is offline
external usenet poster
 
Posts: 72
Default 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.