Link to home
Start Free TrialLog in
Avatar of ClaudeWalker
ClaudeWalker

asked on

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

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello ClaudeWalker,

Check out:

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

Regards,
Chris
Avatar of ClaudeWalker
ClaudeWalker

ASKER

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

The TextStream type is not being recognized by VBA.

Any ideas on why or how to get it recognized?

Thanks,
JOe K.
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

Do you know what library textstream it is?
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

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
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.
THat's fine of course ... it was interesting to do so thank you yourself!

Chris