Show desktop commands in VBA

There is a little icon on the quick launch section of the taskbar in XP that minimizes all of the windows, essentially unconditionally bringing you to the desktop.

Is there a way I can call similar commands (shell or otherwise) in VBA?
[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop

Open in new window

ClaudeWalkerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Chris BottomleyConnect With a Mentor Commented:
Scripting runtime ... but I left the definition in by mistake ... this ought to work without it.

Chris
Sub goDesktop2()
Dim outputPath As String
Dim outputFileName As String
Dim outputfile As Object
Dim fso As Object
Dim WShel  As Object
Dim s As String
    
    On Error Resume Next
    outputPath = "c:\deleteme"
    outputFileName = "nirmal.scf"
    If Right(outputPath, 1) = "\" Then outputPath = Left(outputPath, Len(outputPath) - 1)
    s = outputPath & "\" & outputFileName
    On Error Resume Next
    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FolderExists(outputPath) Then
        fso.CreateFolder outputPath
    End If
    Set outputfile = fso.CreateTextFile(s, True)
    outputfile.WriteLine "[Shell]"
    outputfile.WriteLine "Command = 2"
    outputfile.WriteLine "IconFile=explorer.exe,3"
    outputfile.WriteLine "[Taskbar]"
    outputfile.WriteLine "Command=ToggleDesktop"
    outputfile.Close
    Set WShel = CreateObject("WScript.Shell")
    WShel.Run s
End Sub
 
Sub clearUp()
Dim fso As Object
Dim s As String    
    Set fso = CreateObject("Scripting.FileSystemObject")
    s = "C:\deleteme\nirmal.scf"
    fso.DeleteFile s, True
End Sub

Open in new window

0
 
Chris BottomleyCommented:
Hello ClaudeWalker,

Check out:

http://www.freevbcode.com/ShowCode.asp?ID=7921

Regards,
Chris
0
 
ClaudeWalkerAuthor Commented:
This is definitely on the right track.

Is there a way to do this without creating a file?  Is there a way to just call the commands?

Thanks,
JOe K.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Chris BottomleyCommented:
ClaudeWalker,

Not that I know of.  Note I have just cloned them into two subs ... one to goto the desktop, (goDesktop) and one to delete the file, (clearUp) if you want to.

chris_bottomley
Sub goDesktop()
Dim fso As Object
Dim WShel  As Object
Dim texts As TextStream
Dim s As String
Dim intDelayCount As Integer
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    s = "C:\deleteme\nirmal.scf"
    Set texts = fso.CreateTextFile(s)
    texts.WriteLine "[Shell]"
    texts.WriteLine "Command = 2"
    texts.WriteLine "IconFile=explorer.exe,3"
    texts.WriteLine "[Taskbar]"
    texts.WriteLine "Command=ToggleDesktop"
    Set WShel = CreateObject("WScript.Shell")
    WShel.Run s
End Sub
Sub clearUp()
Dim fso As Object
Dim s As String
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    s = "C:\deleteme\nirmal.scf"
    fso.DeleteFile s, True
End Sub

Open in new window

0
 
ClaudeWalkerAuthor Commented:
The TextStream type is not being recognized by VBA.

Any ideas on why or how to get it recognized?

Thanks,
JOe K.
0
 
Chris BottomleyCommented:
I'm not sure how to late define textstream ... it needs a reference that I have already enabled but not everyone does so I prefer late binding.  Drivel aside I have re-written ... hopefully this one will flow.  The file delete sub is unchanged, but included for completeness.

Chris
Sub goDesktop2()
Dim outputPath As String
Dim outputFileName As String
Dim outputfile As Object
Dim fso As Object
Dim WShel  As Object
Dim texts As TextStream
Dim s As String
    
    On Error Resume Next
    outputPath = "c:\deleteme"
    outputFileName = "nirmal.scf"
    If Right(outputPath, 1) = "\" Then outputPath = Left(outputPath, Len(outputPath) - 1)
    s = outputPath & "\" & outputFileName
    On Error Resume Next
    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FolderExists(outputPath) Then
        fso.CreateFolder outputPath
    End If
    Set outputfile = fso.CreateTextFile(s, True)
    outputfile.WriteLine "[Shell]"
    outputfile.WriteLine "Command = 2"
    outputfile.WriteLine "IconFile=explorer.exe,3"
    outputfile.WriteLine "[Taskbar]"
    outputfile.WriteLine "Command=ToggleDesktop"
    outputfile.Close
    Set WShel = CreateObject("WScript.Shell")
    WShel.Run s
End Sub
 
Sub clearUp()
Dim fso As Object
Dim s As String    
    Set fso = CreateObject("Scripting.FileSystemObject")
    s = "C:\deleteme\nirmal.scf"
    fso.DeleteFile s, True
End Sub

Open in new window

0
 
ClaudeWalkerAuthor Commented:
Do you know what library textstream it is?
0
 
ClaudeWalkerAuthor Commented:
I ended up just saving the file in a static location on the network and then used Application.FollowHyperlink  "S:\Show Desktop.scf"


Thanks for your help,
JOe K.
0
 
Chris BottomleyCommented:
THat's fine of course ... it was interesting to do so thank you yourself!

Chris
0
All Courses

From novice to tech pro — start learning today.