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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris BottomleySoftware Quality Lead EngineerCommented:
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
Chris BottomleySoftware Quality Lead EngineerCommented:
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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 BottomleySoftware Quality Lead EngineerCommented:
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
Chris BottomleySoftware Quality Lead EngineerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 BottomleySoftware Quality Lead EngineerCommented:
THat's fine of course ... it was interesting to do so thank you yourself!

Chris
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.