Hi all,
Is there a way to disable or hide a desktop shortcut using VBA code? I would like to hide a shortcut until some of my code is finished running.
Thanks,
Michael Read
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Disable a desktop shortcut
I have good news and bad news: it is possible to toggle the hidden attribute of a desktop shortcut – but it doesn’t disable it. Here’s the code, perhaps it will work better for you. Plan B would be to perhaps move it temporarily, or disable the command string it contains. The former could be accomplished using the FileSystemObject, the latter probably requires further exploration of the WshShell object.
Sub Tester() 'determine desktop folder (might not work for individual profiles) Dim wshShell As Object, strDesktopFolder As String, strPath As String Set wshShell = CreateObject("WScript.Shell") strDesktopFolder = wshShell.SpecialFolders("desktop") Set wshShell = Nothing 'toggle hidden status of file - example of Word shortcut strPath = strDesktopFolder & "" & "microsoft word.LNK" If ToggleFileHidden(strPath) = False Then MsgBox "File not found" Else MsgBox "Hidden attribute toggled!" End If End Sub Function ToggleFileHidden(strFullPath As String) As Boolean 'set a reference to Microsoft Scripting Runtime 'set file object and check attributes Dim fso As FileSystemObject, myFile As File Set fso = New FileSystemObject If Not fso.FileExists(strFullPath) Then ToggleFileHidden = False Set fso = Nothing Exit Function End If Set myFile = fso.GetFile(strFullPath) If myFile.Attributes And Hidden Then myFile.Attributes = myFile.Attributes - Hidden Else myFile.Attributes = myFile.Attributes + Hidden End If ToggleFileHidden = True Set myFile = Nothing Set fso = Nothing End Function
I tried it and it works, although I modified it to fit my purpose. The shortcut properties do change, however, like you say, the shortcut is still there.
A great tool would be a “windows script recorder”, similar to the macro recorder in Excel, that could record scripts across the Office applications and/or within the Windows environment.
Thanks Jefferson,
Michael Read
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications