Question : Path To File Is Truncated...Can I Show The Full Path

I am returning a path to a filename as a string, but it is truncating the filename:

\\network\folder1\longfil~1\filena~1.txt

I would like to return the entire filename:

\\network\folder1\longfile folder\filename here.txt

Is there a way to do this?  Because I can not return the filename correctly I am getting all kinds of errors.  I am using code from:
From http://support.microsoft.com/?kbid=311147

to relink OLE objects.  Help is appreciated, and urgently needed.  The function below is where the Path is returned truncated:

Function GetLinkedPath(objOLE As Variant) As Variant
Dim strChunk As String
Dim pathStart As Long
Dim pathEnd As Long
Dim path As String
If Not IsNull(objOLE) Then
    'Convert string to Unicode.
    strChunk = StrConv(objOLE, vbUnicode)
  MsgBox strChunk
   
    pathStart = InStr(1, strChunk, ":\", 1) - 1

    'If mapped drive path is not found, try UNC path.
    If pathStart <= 0 Then pathStart = InStr(1, strChunk, "\\", 1)

    'If either drive letter path or UNC path is found, determine
    'the length of the path by searching for the first null
    'character Chr(0) after the path was found.
    If pathStart > 0 Then
        pathEnd = InStr(pathStart, strChunk, Chr(0), 1)
        path = Mid(strChunk, pathStart, pathEnd - pathStart)
          MsgBox path
        GetLinkedPath = path
        Exit Function
    End If
Else
    GetLinkedPath = Null
End If
End Function

Answer : Path To File Is Truncated...Can I Show The Full Path

Hi,

You can use the Windows API function GetLongPathName to 'convert' the short (8.3 format) as follows:

Option Explicit

Private Declare Function GetLongPathName _
            Lib "kernel32" _
          Alias "GetLongPathNameA" _
         (ByVal lpszShortPath As String, _
          ByVal lpszLongPath As String, _
          ByVal cchBuffer As Long) As Long
Function strGetLongName(strShortPath As String) As String

  Dim strBuffer As String * 1000

  If GetLongPathName(strShortPath, strBuffer, Len(strBuffer)) Then
     strGetLongName = Left$(strBuffer, InStr(strBuffer, Chr$(0)))
  End If

End Function


For example:

strShort = "\\network\folder1\longfil~1\filena~1.txt"
strLong = strGetLongName(strShort)

(strLong with then contain "\\network\folder1\longfile folder\filename here.txt")


So, in your function "GetLinkedPath", the line that is:
GetLinkedPath = path
could be changed to:
GetLinkedPath = strGetLongName(path)

Or you could simply use as follows:
strFilename = strGetLongName(GetLinkedPath(<your OLE object>))

BFN,

fp.
Random Solutions  
 
programming4us programming4us