ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   windows file shortcut using vb (https://www.excelbanter.com/excel-programming/326461-windows-file-shortcut-using-vbulletin.html)

Mike C

windows file shortcut using vb
 
i would like vb to create a shortcut to a file i have and put that shortcut
into a parent folder. I think that the ShellLink function will work but i
don't know how to do it. Any suggestions? im stumped.
Thanks

Bob Phillips[_6_]

windows file shortcut using vb
 
Here is some code

Sub CreateShortCut()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPath As String

Set oWSH = CreateObject("WScript.Shell")
sPath = "C:\myFolder"

Set oShortcut = oWSH.CreateShortCut(sPath & "\" & _
ActiveWorkbook.Name & ".lnk")
With oShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With

Set oWSH = Nothing

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike C" wrote in message
...
i would like vb to create a shortcut to a file i have and put that

shortcut
into a parent folder. I think that the ShellLink function will work but i
don't know how to do it. Any suggestions? im stumped.
Thanks




Mike C

windows file shortcut using vb
 
Thanks that helped me a whole lot!

"Bob Phillips" wrote:

Here is some code

Sub CreateShortCut()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPath As String

Set oWSH = CreateObject("WScript.Shell")
sPath = "C:\myFolder"

Set oShortcut = oWSH.CreateShortCut(sPath & "\" & _
ActiveWorkbook.Name & ".lnk")
With oShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With

Set oWSH = Nothing

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike C" wrote in message
...
i would like vb to create a shortcut to a file i have and put that

shortcut
into a parent folder. I think that the ShellLink function will work but i
don't know how to do it. Any suggestions? im stumped.
Thanks






All times are GMT +1. The time now is 08:22 AM.

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