Link to home
Start Free TrialLog in
Avatar of stephenlecomptejr
stephenlecomptejrFlag for United States of America

asked on

Need help with vbscript to create shortcut on desktop-refuses to run cause of correct syntax error.

I'm trying to create a shortcut automatically using vbs script but it refuses to run all the way through  because it throws a char: 2 error - object doesn't support this property or method which happens on this particular line item:

WshShell = CreateObject("Wscript.shell")

Please note attachment that shows error.

I took this code from this website but it hasn't worked out for me.

https://support.microsoft.com/en-us/help/244677/how-to-create-a-desktop-shortcut-with-the-windows-script-host

Public Sub CreateIconToDesktop()

 Dim WshShell
 Dim strDesktop
 Dim oMyShortCut
 WshShell = CreateObject("Wscript.shell")
 strDesktop = WshShell.SpecialFolders("Desktop")
 oMyShortcut = WshShell.CreateShortcut(strDesktop + "\Sample.lnk")
 'oMyShortcut.WindowStyle = 3  &&Maximized 7=Minimized  4=Normal 
 oMyShortcut.IconLocation = "Q:\Dialer\_dbadmin\icons\logocampaign.ico"
 oMyShortcut.TargetPath = "Q:\Dialer\dialercampaigns.accdb"
 'oMyShortCut.Hotkey = "ALT+CTRL+F"
 oMyShortCut.Save

End Sub

Open in new window

Avatar of Bill Prew
Bill Prew

Are you running this as a VBS script, or as VBA code inside an Office app?

One thing I do see wrong if a stand alone VBS, you need a Set when assigning object variables, like:

Set WshShell = CreateObject("Wscript.shell")


»bp
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stephenlecomptejr

ASKER

Dude you the man!  Thank you so much.
Welcome, glad that helped.

~bp