File Location code

R

Rohit Thomas

Hello All,

I'm using the following modified code that was posted
by "Dan E." several weeks ago to write the path of a file
out to a cell. Below is the code:

FileName = Application.GetOpenFilename("Text Files _
(*.txt), *.txt")
CellLocation = Len(FileName) + 1 - InStr(1, StrReverse _
(FileName), "\")
FilePath = Mid(FileName, 1, CellLocation)
Range("G46").Value = FilePath

When I run this code using Excel 97, it gives me the
following error: Sub or Funtion not defined for
"StrReverse". Works fine on Excel 2K, what am I missing?

Thanks in advance,
Rohit
 
H

Harald Staff

Hi Rohit

Excel 97 is older than Excel 2000, which is older than Excel XP. Things (here StrReverse)
are invented and added to each new version. Great thing is that nothing is removed. For
cross-version development you /must/ use the oldest version to develop on, or you're
working blindfolded and will be rewarded by error messages like this.
 
R

Rohit Thomas

Herald,

Can I use something in it's place to get the desired
result that I'm looking for? Any suggestions on how I can
use the GetOpenFileName dialog to write the path of a file
to a cell?

Rohit
-----Original Message-----
Hi Rohit

Excel 97 is older than Excel 2000, which is older than
Excel XP. Things (here StrReverse)
are invented and added to each new version. Great thing
is that nothing is removed. For
cross-version development you /must/ use the oldest
version to develop on, or you're
 
D

Dan E

Mark,

It's StrReverse and it reverses a string
ie ABC -> CBA

InStrRev is a search tool for searching for one string
within another from the end to the beginning, they are
nothing alike.

Dan E
 
H

Harald Staff

One way:

Sub test()
Dim filename As String, L As Long
filename = Application.GetOpenFilename("Text Files " & _
"(*.txt), *.txt")
For L = Len(filename) To 1 Step -1
If Mid$(filename, L, 1) = "\" Then Exit For
Next
MsgBox Left$(filename, L - 1)
End Sub

If a folder is all you need selected, then see Jim Rech's "Browse for folder" at
http://www.bmsltd.co.uk/MVP/Default.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top