Creating Shortcuts

B

Bear

I have a script running in an EXCEL document that creates new workbooks
based on input from the user. It then saves the file in a set location.

I would like to adjust the code to creat a shortcut to the new file and
place the shortcut in a different folder.

Is there a way to do this?
 
S

Steve Yandl

In the VBE editor, go to Tools > References and set a reference to 'Windows
Script Host Object Model"

Now, the code below would create a shortcut named "Book1Shortcut" located in
the folder "C:\Test\myfolder" with the target Excel file of the shortcut
being "C:\Test\Book1.xls".

Dim wsh As WshShell
Dim myShort As WshShortcut
Set wsh = New WshShell
Set myShort = wsh.CreateShortcut("C:\Test\myfolder\Book1Shortcut.lnk")
myShort.TargetPath = "C:\Test\Book1.xls"
myShort.Save
Set wsh = Nothing

Steve
 
Top