
Converting long filenames to short
->Hi,
->
->In one of my VB5.0 projects I want to control an instance of Excel
5.0
->by means of OLE Automation, and open and save spreadsheets there. Am
I
->right in assuming that I can only deal with short (DOS-based)
filenames
->when doing so, and if so, is there a simple way to convert long
Win95
->filenames to the DOS counterparts in VB 5.0?
->
Here is a snippet of code that should work for you:
Private Declare Function GetShortPathName Lib "kernel32" Alias
"GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath
As String, ByVal cchBuffer As Long) As Long
Function GetShorty(sFileName As String)
Dim lpShortFileName As String
Dim lSize As Long
Dim lSucc As Long
lpShortFileName = Space$(128)
lSize = Len(lpShortFileName)
'* Fetch the short file name
lSucc = GetShortPathName(sFileName, lpShortFileName, lSize)
'* Discard the trailing spaces and null character.
GetShorty = Left$(lpShortFileName, lSucc)
End Function
Private Sub Form_Load()
Debug.Print GetShorty("c:\Windows\Favorites\SoftCircuits Home
Page.url")
End Sub
Paul
~~~~