ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Extract Target path from a shortcut (https://www.excelbanter.com/excel-programming/350200-extract-target-path-shortcut.html)

WhytheQ

Extract Target path from a shortcut
 
I know how to add a target path to a created shortcut:

Dim WSHShell As Object
Dim MyShortcut As Object

Set WSHShell = CreateObject("WScript.Shell")
Set MyShortcut = WSHShell.CreateShortcut(pathwayhere & ".lnk")

With MyShortcut
.targetpath = targetpathwayhere
.Save
End With

.........but if I already have a created shortcut then how do I extract
the target pathway from it, as a string??

any help greatly appreciated

Jason.


Norman Jones

Extract Target path from a shortcut
 
Hi Jason,

Try something like:

'=============
Public Sub Tester()
Dim WSHShell As Object
Dim MyShortcut As Object
Dim sDesktoPath As String
Const sShortcutName As String = "YourShortcutName"

Set WSHShell = CreateObject("WScript.Shell")

sDesktopPath = WSHShell.SpecialFolders("Desktop")

Set MyShortcut = WSHShell.CreateShortcut(sDesktopPath _
& "\" & sShortcutName & ".lnk")

MsgBox MyShortcut.TargetPath

End Sub
'<<=============


---
Regards,
Norman


"WhytheQ" wrote in message
oups.com...
I know how to add a target path to a created shortcut:

Dim WSHShell As Object
Dim MyShortcut As Object

Set WSHShell = CreateObject("WScript.Shell")
Set MyShortcut = WSHShell.CreateShortcut(pathwayhere & ".lnk")

With MyShortcut
.targetpath = targetpathwayhere
.Save
End With

........but if I already have a created shortcut then how do I extract
the target pathway from it, as a string??

any help greatly appreciated

Jason.




WhytheQ

Extract Target path from a shortcut
 
Very nice Norman!
It was using the "CreateShortcut" method that fooled me: I had it in my
head that this would create a new shortcut rather than get a hook on an
existing one !!

all seems to work ok
thanks again
Jason



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

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