Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Variable File Name

We are using -

FileOpenName = Application.GetOpenFilename("Text Files
(*.txt),*.txt", 1, "Open IFCAP Text File", , False)

to prompt the user for the file to be opened. Later in our
macro we want to switch from another workbook to this
workbook, but can't figure out how to get the workbook
name as a variable from the FileOpenName variable.

The FileOpenName could be "C:\FOLDER1\FOLDER2\FNAME.xls."
It could have multiple folders and the filename can vary.
We can not see how to get the FNAME.xls extracted. We
looked at Instr but couldn't see how to use it to get what
we want.

Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Variable File Name

You can use the Split97 function for this if it must work in Excel 97-2003
See the example I use in this Zip sub to get the file name
http://www.rondebruin.nl/zip.htm

See the VBA help for Split if you use 2000 or higher



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Trevor" wrote in message ...
We are using -

FileOpenName = Application.GetOpenFilename("Text Files
(*.txt),*.txt", 1, "Open IFCAP Text File", , False)

to prompt the user for the file to be opened. Later in our
macro we want to switch from another workbook to this
workbook, but can't figure out how to get the workbook
name as a variable from the FileOpenName variable.

The FileOpenName could be "C:\FOLDER1\FOLDER2\FNAME.xls."
It could have multiple folders and the filename can vary.
We can not see how to get the FNAME.xls extracted. We
looked at Instr but couldn't see how to use it to get what
we want.

Any ideas?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Variable File Name

What about:
newString = Mid(yourString, InStrRev(yourString, "\", , vbTextCompare) + 1)

This will get everything after the last "\" or everything in the string, if no backslash is present.

-Dan

"Ron de Bruin" wrote:

You can use the Split97 function for this if it must work in Excel 97-2003
See the example I use in this Zip sub to get the file name
http://www.rondebruin.nl/zip.htm

See the VBA help for Split if you use 2000 or higher



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Trevor" wrote in message ...
We are using -

FileOpenName = Application.GetOpenFilename("Text Files
(*.txt),*.txt", 1, "Open IFCAP Text File", , False)

to prompt the user for the file to be opened. Later in our
macro we want to switch from another workbook to this
workbook, but can't figure out how to get the workbook
name as a variable from the FileOpenName variable.

The FileOpenName could be "C:\FOLDER1\FOLDER2\FNAME.xls."
It could have multiple folders and the filename can vary.
We can not see how to get the FNAME.xls extracted. We
looked at Instr but couldn't see how to use it to get what
we want.

Any ideas?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Variable File Name

Sure you can (in excel 2000 and later).

Another way is

Public Function GetName(sFname As String)
Dim i As Long, sFname1 As String, s As String
Dim j as Long
If InStr(sFname, "\") Then
sFname1 = ""
i = Len(sFname)
j = 0
Do
s = Mid(sFname, i, 1)
If s < "\" Then
j = j + 1
End If
i = i - 1
Loop Until s = "\"
sFname1 = Right(sFname, j)
Else
sFname1 = sFname
End If
GetName = sFname1
End Function

This is slower, but should work in all versions.


"DanOFin" wrote in message
...
What about:
newString = Mid(yourString, InStrRev(yourString, "\", , vbTextCompare) +

1)

This will get everything after the last "\" or everything in the string,

if no backslash is present.

-Dan

"Ron de Bruin" wrote:

You can use the Split97 function for this if it must work in Excel

97-2003
See the example I use in this Zip sub to get the file name
http://www.rondebruin.nl/zip.htm

See the VBA help for Split if you use 2000 or higher



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Trevor" wrote in message

...
We are using -

FileOpenName = Application.GetOpenFilename("Text Files
(*.txt),*.txt", 1, "Open IFCAP Text File", , False)

to prompt the user for the file to be opened. Later in our
macro we want to switch from another workbook to this
workbook, but can't figure out how to get the workbook
name as a variable from the FileOpenName variable.

The FileOpenName could be "C:\FOLDER1\FOLDER2\FNAME.xls."
It could have multiple folders and the filename can vary.
We can not see how to get the FNAME.xls extracted. We
looked at Instr but couldn't see how to use it to get what
we want.

Any ideas?






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File name and Sheet name a variable. Duane Excel Discussion (Misc queries) 2 January 14th 10 05:18 PM
Variable File Name Tigerxxx Excel Discussion (Misc queries) 4 March 8th 09 05:24 AM
calling a value from another file using a variable in the file nam DA_Potts[_2_] Excel Worksheet Functions 3 December 3rd 07 12:25 AM
calling a value from another file using a variable in the file nam DA_Potts[_2_] Excel Discussion (Misc queries) 4 December 2nd 07 11:09 PM
Variable File Name [email protected] Excel Worksheet Functions 1 June 18th 06 10:36 AM


All times are GMT +1. The time now is 05:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"