I am using the following code (as found here) in Word2010 to find the target path of a shortcut:
Function Getlnkpath(ByVal Lnk As String)
On Error Resume Next
With CreateObject("Wscript.Shell").CreateShortcut(Lnk)
Getlnkpath = .TargetPath
.Close
End With
End Function
Sub GetLinkPath()
MsgBox Getlnkpath("yourshortcutnamehere")
End Sub
When I run the code as shown (modified to use my shortcut name) I get the following error:
Run-time error '438':
Object doesn't support this property or method
and the .Close line is highlighted for debug. When I comment out .Close the script works fine.
Does this cause problems if the shell doesn't close? I've read that .Close isn't necessary for Wscript.Shell but can't confirm that.
There is no Close method to the shortcut object and that is why you are getting the error. This link lists basic operations of WScript.Shell.
If you are intending to dispose the shell object, the best way to do would be
Set objWshShell = WScript.CreateObject("WScript.Shell")
With objWshShell.CreateShortcut(Lnk)
.Save
Getlnkpath = .TargetPath
End With
Set objWshShell = Nothing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With