Create shortcut using VBA

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
Hi everyone. Long time no post...is it possible to create a shortcut to a workbook on my desktop using VBA?

Thanks for any help!

Dave

:beerchug:
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Thanks for the link fructose...I can't use an add-in however for this workbook...it is a handy one so I downloaded it anyway! :lol:

I think I'm just going to use the following:

Code:
Sub Create_ShortCut()
        
' needs reference to Windows Script Host Object Model
Dim sc_Path As String
Dim WSHShell As IWshShell
Dim MyShortcut As IWshShortcut_Class

sc_Path = "C:\"
Set WSHShell = New IWshShell_Class
Set MyShortcut = WSHShell.CreateShortcut(sc_Path & "\" & ActiveWorkbook.Name & ".lnk")

With MyShortcut
    .TargetPath = ActiveWorkbook.FullName
    .Save
End With

Set WSHShell = Nothing
    
End Sub

Even though I'll need to set the reference to the Windows Script Host Object Model...

Thanks and have a good day,

Dave :beerchug:
 
Upvote 0
Dave

You could probably avoid needing to create the reference by using late binding.

You would need to adjust the code to do that, I'm not exactly sure how but I'll see if I can find out and post back.

Something like this perhaps.
Code:
Sub Create_ShortCut()
       
' needs reference to Windows Script Host Object Model
Dim sc_Path As String
Dim WSHShell As Object
Dim MyShortcut As Object

sc_Path = "C:"
Set WSHShell = CreateObject("WScript.Shell")

Set MyShortcut = WSHShell.CreateShortcut(sc_Path & "\" & ActiveWorkbook.Name & ".lnk")

With MyShortcut
    .TargetPath = ActiveWorkbook.FullName
    .Save
End With

Set WSHShell = Nothing
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,885
Messages
6,181,587
Members
453,055
Latest member
cope7895

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top