Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA (Word 97, windows 98) Reading the path of a shortcut.

Status
Not open for further replies.

ThinLizzy

Programmer
May 30, 2002
12
NL
I would like the read the path of a shortcut file.
I tried some VB controls but they wouldn't work in
Word 97.

please help.
 
Hello Thinlizzy,

Try using this to parse path and file names:

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.

Hope this helps,
Pete
 
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:

TargetPathOfShortCut = _
TheFunctionOrObjectIamLookingFor(strLink)

End Function


Do you know a solution for this ?
It is realy fustrating problem for me....
 
By the way, I found a solution!

See thread711-283365

ThinLizzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top