Public Function GetPath()
Dim strPathAndFile As String
Dim lngCharacterPosition As Long
Dim strPath As String
Dim strFileName As String
'Setting the string that contains the shortcut's path and file name to a static value
'for testing. Set the string however you need to when actually using this code.
strPathAndFile = "C:\WINNT\Profiles\pete\Desktop\Some Shortcut.lnk"
'Initialize the starting character position.
lngCharacterPosition = 1
'Start the loop that will count the rest of them.
'The InStr search will continue from just after the found occurence of "\" (standard
'path delimiter character) until no more are found, which is when InStr returns 0.
Do Until Strings.InStr(lngCharacterPosition + 1, strPathAndFile, "\" = 0
lngCharacterPosition = Strings.InStr(lngCharacterPosition + 1, strPathAndFile, "\"
Loop
'lngCharacterPosition now contains the last occurence of the "\" character.
'So set the path name as follows:
strPath = Strings.Left(strPathAndFile, lngCharacterPosition)
'If you don't want a trailing "\", use:
'strPath = Strings.Left(strPathAndFile, lngCharacterPosition - 1) 'instead.
'Should you want the file name as well, set it as follows:
strFileName = Strings.Right(strPathAndFile, Strings.Len(strPathAndFile) - lngCharacterPosition)
GetPath = strPath
End Function
This works quite well with the above path to a shortcut.
If this is not what you meant or needed, please clarify how I can help you.
Thanks for your answer, but that was not quit what i was looking for.
I want to realy reed the path of a shortcut file in a
directory, see beneth:
Public Function TargetPathOfShortCut() As String
Dim strLink As String
strLink = Dir("c:\*.LNK" ' Return first *.LNK file
' (this link to another File
' for instance mylink.LNK
' What I want to know is to
' which file this link
' is pointing
' Something like:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.