Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Another Window (Windows Folder) with a Macro

Status
Not open for further replies.

Sparky1157

Programmer
Aug 19, 2016
30
US
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
====================
 
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!!!
 
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top