Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable a desktop shortcut

    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

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: 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.

    <pre>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</pre>


  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable a desktop shortcut

    Thanks Jefferson, I think!

    Boggles my marbles at first, but I think I get the drift.

    Thanks for your time,
    Michael Read

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Disable a desktop shortcut

    I forgot to mention, if you are in Word, you can get the name of the desktop folder this way:

    strDesktop = System.PrivateProfileString("", _
    "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentV ersionExplorerShell Folders", _
    "Desktop")

  5. #5
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Disable a desktop shortcut

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •