ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ShortName (https://www.excelbanter.com/excel-programming/421981-shortname.html)

Robin Clay[_4_]

ShortName
 
Greetings ! and a Happy New Year !

This works OK:-
For J = 1 To .FoundFiles.Count Step 1
myText = .FoundFiles(J)
....

returning the long file name of each file in turn
But how can I get the SHORT filename of each in turn ?

myText = .FoundFiles(J).ShortName

doesn't work.


Regards

Robin

JLGWhiz

ShortName
 
You could put this in your standard module.

Sub ShowShortName(filespec)
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
s = "The short name for " & "" & UCase(f.Name)
s = s & "" & vbCrLf
s = s & "is: " & "" & f.ShortName & ""
MsgBox s, 0, "Short Name Info"
End Sub

Then use it like a Function to display a pop up message:

Sub shw()
ShowShortName(MyText)
End Sub



"Robin Clay" wrote:

Greetings ! and a Happy New Year !

This works OK:-
For J = 1 To .FoundFiles.Count Step 1
myText = .FoundFiles(J)
...

returning the long file name of each file in turn
But how can I get the SHORT filename of each in turn ?

myText = .FoundFiles(J).ShortName

doesn't work.


Regards

Robin


Robin Clay[_4_]

ShortName
 
Bravo !

Here's what I used:-

Function ShortName(filespec)
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
ShortName = f.ShortName
End Function

.... and then in my main routine:-
For J = 1 To .FoundFiles.Count Step 1
myText = ShortName(.FoundFiles(J))
etc.

Thank you very much indeed.


Regards

Robin


"JLGWhiz" wrote:

You could put this in your standard module.

Sub ShowShortName(filespec)
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
s = "The short name for " & "" & UCase(f.Name)
s = s & "" & vbCrLf
s = s & "is: " & "" & f.ShortName & ""
MsgBox s, 0, "Short Name Info"
End Sub

Then use it like a Function to display a pop up message:

Sub shw()
ShowShortName(MyText)
End Sub



"Robin Clay" wrote:

Greetings ! and a Happy New Year !

This works OK:-
For J = 1 To .FoundFiles.Count Step 1
myText = .FoundFiles(J)
...

returning the long file name of each file in turn
But how can I get the SHORT filename of each in turn ?

myText = .FoundFiles(J).ShortName

doesn't work.


Regards

Robin



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

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