INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Accessing Another Window (Windows Folder) with a Macro

Accessing Another Window (Windows Folder) with a Macro

(OP)
I've been using the Macro Editor to create some automation in our Reflection sessions, but now I would also like to create a macro that will turn off the Navigation Pane for a particular folder that's opened on my desktop (the folder containing links to my macros). Here's the code I have so far...

====================
' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim Explorer As Object
Set Explorer = CreateObject("Explorer.Application")
If (Explorer is Nothing) Then
Msgbox "Could not create the Explorer System object. Stopping macro playback."
STOP
End If
Set Sessions = Explorer.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 100 ' milliseconds

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = Explorer.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' This section of code contains the recorded events
Sess0.Screen.Sendkeys("<Alt+D>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab><Tab>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Down>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("l")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("n")
End Sub
====================

...but I have no idea how to properly select the folder window and how to establish it as the appropriate SESSION to send the keystrokes to.

Some help would be greatly appreciated!

Thanks in advance!!!

I also tried the following, without success:

====================
Sub Main()
Dim Explorer As Object
Set Explorer = GetObject("Explorer.Application.1")
If Explorer is Nothing Then
Msgbox "Could not find Windows Explorer Window."
STOP
End If

Explorer.Screen.Sendkeys("<Alt+D>")
Explorer.Screen.WaitHostQuiet(g_HostSettleTime)
Explorer.Screen.Sendkeys("<Tab><Tab>")
Explorer.Screen.WaitHostQuiet(g_HostSettleTime)
Explorer.Screen.Sendkeys("<Down>")
Explorer.Screen.WaitHostQuiet(g_HostSettleTime)
Explorer.Screen.Sendkeys("l")
Explorer.Screen.WaitHostQuiet(g_HostSettleTime)
Explorer.Screen.Sendkeys("n")
End Sub
====================

RE: Accessing Another Window (Windows Folder) with a Macro

(OP)
Since my pervious post earlier this week I'm continually researching & trying other things. The following code has been successful in opening an occurrence of Windows Explorer:

==========================
Sub Main()
Dim SpecialFolderPath As String

hWndCalc& = Shell("C:\WINDOWS\explorer.exe", 1)
SpecialFolderPath = "G:\Common\...\Desktop Macros"


' Explorer.Screen.Sendkeys("<Alt+D>")
' Explorer.Screen.WaitHostQuiet(g_HostSettleTime)
' Explorer.Screen.Sendkeys("<Tab><Tab>")
' Explorer.Screen.WaitHostQuiet(g_HostSettleTime)
' Explorer.Screen.Sendkeys("<Down>")
' Explorer.Screen.WaitHostQuiet(g_HostSettleTime)
' Explorer.Screen.Sendkeys("l")
' Explorer.Screen.WaitHostQuiet(g_HostSettleTime)
' Explorer.Screen.Sendkeys("n")
End Sub
==========================

However, I don't know to get Windows Explorer to the appropriate directory (i.e., "G:\Common\...\Desktop Macros"), or how to send the key sequences to the window to get the Navigation Pane turned off....

*sigh*

Any ideas would be most appreciated!

Oh, and then I ran across some other functions ... FINDWINDOW and SHOWWINDOW that may be useful in this instance, but I have no documentation to rely on in order to figure out how best to approach that scenario....

PLEASE NOTE: ALL OF THE CODING EXAMPLES ABOVE DO NOT WORK AS I WOULD LIKE - I DO NOT KNOW WHAT IS WRONG WITH THE CODE - PLEASE HELP!!!

RE: Accessing Another Window (Windows Folder) with a Macro

Its good to know about all this.

RE: Accessing Another Window (Windows Folder) with a Macro

(OP)
Within the Attachmate Macro Editor I was able to compile and run the following macro, which opens a Windows Explorer window and turns off the navigation pane.

--------------------------------------------------
' Internal Functions
'
' Set up sleep subroutine derived from the C:\Windows\System32\kernel32.dll file.
'
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

Sub Main()
'--------------------------------------------------------------------------------
Dim FolderPath As String
FolderPath = "G:\Desktop Folder"

Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "explorer"
Sleep 3000
WshShell.AppActivate "Explorer"
'
' Set explorer to folder path.
'
WshShell.SendKeys("%d")
WshShell.SendKeys(FolderPath)
WshShell.SendKeys("{Enter}")
Sleep 2000
'
' Turn off navigation pane.
'
WshShell.SendKeys("%d")
Sleep 100
WshShell.SendKeys("{Tab}")
Sleep 100
WshShell.SendKeys("{Tab}")
Sleep 100
WshShell.Sendkeys("{Down}")
Sleep 100
WshShell.Sendkeys("l")
Sleep 100
WshShell.Sendkeys("n")

End Sub
--------------------------------------------------

This was accomplished with the help of the VB Script community.

Thanks for all the assistance!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close