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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Resize Application Window 3

Status
Not open for further replies.

Sparky1157

Programmer
Aug 19, 2016
30
US
I've tried 2 methods of resizing an application window, but each one gives me a compile error.

Method #1
WshShell.moveTo 1030,110 ' Moves the window position
' horizontally, vertically and
WshShell.resizeTo 225,175 ' changes the width and height

Method #2
With Application
.WindowState = wdWindowStateNormal
.Resize Width:=InchesToPoints(7), Height:=InchesToPoints(6)
End With

Preliminary file contents:
Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "explorer"
Sleep 3000
WshShell.AppActivate "Explorer"

Any suggestions would be most appreciated!
 
Method 1, I'm not familiar with the moveTo method of the wscript shell

Method 2, is VBA.

How are you executing your vbscript?
 
In #2, is it VBA, in what application, what application you try to resize?

combo
 
I'm using Attachmate Extra! Macro Editor, and normally do only Attachmate-type macros. However, in this situation I'm opening a Windows Explorer window in order to display the macro files for selection. I would like to resize the window, and at first posted my question on the Attachmate forum. One of the guys there said I should probably post the question here instead.

I've got the Windows Explorer opening properly, and direct it to the correct location of the macro files. I've also been able to turn off the navigation pane using the macro. However, I don't know how to resize the window, or even if that's possible using the macro language provided by the Attachmate Extra! macro editor.

I launch this macro by double-clicking an icon on my desktop. It's a .EBM file. Hopefully this information provides additional insight into what I'm doing, and how I'm trying to do it.

Thanks!
 
I don't see any way to resize a Windows Explorer window using any native program including vbscript. There may be third party software that does that, no idea. There are ways to control the default position Explorer opens up in, but that needs to be done manually machine to machine.
 
okay - well, thank you for your attention to this matter!
 
I don't see any way to resize a Windows Explorer window using any native program including vbscript.

Sounds like what I told you, in other words.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
>I don't see any way to resize a Windows Explorer window using any native program including vbscript

Of course you can ... ;-)

This example assumes you have opened a single Windows Explorer window (if you have more than one, it resizes them all):

Code:
[blue]Public Sub Example()
    Dim myShell
    Dim myExplorerWindow
    
    Set myShell = CreateObject("Shell.Application")
    
    For Each myExplorerWindow In myShell.Windows
        On Error Resume Next
        If myExplorerWindow.Parent.Name = "File Explorer" Then
            myExplorerWindow.Width = 800
            myExplorerWindow.Height = 400
            [green]' Additinaly use .Top and .Left to reposition if you require[/green]
            myExplorerWindow.Visible = True
        End If
        On Error GoTo 0
    Next
End Sub[/blue]

Unfortunately not familiar with current versions of Attachmate, so can't give an example of directly integrating this code with it.
 
Very cool! I did not think this could be done, and I have searched in the past. I wonder what other application windows this could be extended to? Seems limited to IE and Explorer windows though.

My only tweak was to change the IF statement to:
Code:
If myExplorerWindow.Parent.Name = [highlight #FCE94F]"Windows Explorer"[/highlight] Then

Big star for that, strongm.

Sparky1157: If you can't get this code working, post what you have tried.
 
Thanks for your feedback! I did try the operation as both strongm and guitarzan indicated:

Sub Main()
Dim myShell
Dim myExplorerWindow

Set myShell = CreateObject("Shell.Application")

For Each myExplorerWindow In myShell.Windows
On Error Resume Next
If myExplorerWindow.Parent.Name = "Windows Explorer" Then
myExplorerWindow.Width = 800
myExplorerWindow.Height = 400
' Additinaly use .Top and .Left to reposition if you require
myExplorerWindow.Visible = True
End If
On Error GoTo 0
Next
End Sub

However, I received compile errors on lines 7, 9-11, 13-14.
 
I also tried incorporating it into my own macro, without success. It doesn't give me a compile error, but gives me a run-time error.

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")

WshShell.Width = 400
WshShell.Height = 800
WshShell.Top = 30
WshShell.Left = 1


End Sub

The run-time error is as follows: no such property or method - Line number: 46 - Stopping macro playback.
 
This rather sugests to me that Attachmate Extra is NOT a vbScript host
 
>My only tweak was to change the IF statement to

Yes, Microsoft changed the Name for Windows 10.
 
OK ... don't give up on me yet, strongm! I found another version of the macro editor which supports a wider array of VB instructions - your example does NOT produce a compile error, and runs just fine!

However, what I had wanted to do in my original macro, which also runs just fine under this alternate version of the macro editor, is open a Windows Explorer window, set the path, turn off the navigation pane, and then resize the window. When I try to combine my macro with yours, it fails to execute and produces a run-time error.

Basically what I guess I need to do is start with your macro suggestion and somehow modify it to accomplish my objectives. In your macro file, how would you execute opening an occurrence of Windows Explorer and setting it as active? Then we don't need to resize every occurrence of Windows Explorer - just the one that's currently active after turning off the Navigation Pane.

Can you help me, strongm?

I'm counting on it!!! [glasses]
 
You want to get the LAST occurrence of a window opening...
Code:
Sub testt()
    Dim myShell
    Dim myExplorerWindow
    Dim iCnt As Integer
    Dim WshShell As Object

    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "explorer"
    
    Set myShell = CreateObject("Shell.Application")
    
    For Each myExplorerWindow In myShell.Windows
        On Error Resume Next
        iCnt = iCnt + 1
        If iCnt = myShell.Windows.Count Then
            If myExplorerWindow.Parent.Name = "File Explorer" Then
                myExplorerWindow.Width = 800
                myExplorerWindow.Height = 400
                ' Additinaly use .Top and .Left to reposition if you require
                myExplorerWindow.Visible = True
                myExplorerWindow.SendKeys ("%d")
            End If
        End If
        On Error GoTo 0
    Next
End Sub


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I've managed to get this combined version of the macro working:
--------------------------------------------------------------
Sub Explorer()

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")

Dim myShell As Object
Dim myExplorerWindow As Object

Set myShell = CreateObject("Shell.Application")

For Each myExplorerWindow In myShell.Windows
On Error Resume Next
If myExplorerWindow.Parent.Name = "Windows Explorer" Then
myExplorerWindow.Width = 280
myExplorerWindow.Height = 820
myExplorerWindow.Top = 150
myExplorerWindow.Left = 1265
myExplorerWindow.Visible = True
End If
On Error GoTo 0
Next

End Sub
--------------------------------------------------------------
But I don't think all of that is necessary....

The cool thing is that it actually WORKS! But we shouldn't need to iterate through a FOR loop for the active window....
 
Sure. Whilst this may look like a lot more code, it is really just a very minor modification. Just remember that this is NOT production quality code, just an example of how it might be done:

Code:
[blue]Public Sub Example()
    Dim myShell
    Dim myExplorerWindow
    Dim FoundExplorerWindow
    Dim ExplorerCount
    
    Set myShell = CreateObject("Shell.Application")
    Set FoundExplorerWindow = Nothing 'Cheat for vbScript
    
    Dim strPath
    
    strPath = "C:\Windows"
    
    ' See if we already have an explorer pointing to required folder
    For Each myExplorerWindow In myShell.Windows
        On Error Resume Next
        If UCase(myExplorerWindow.Document.Folder.Self.Path) = UCase(strPath) Then
            Set FoundExplorerWindow = myExplorerWindow
            Exit For
        End If
        On Error GoTo 0
    Next
    
    
    If FoundExplorerWindow Is Nothing Then 'No existing explorer window
        ExplorerCount = myShell.Windows.Count
        'myShell.Explore "c:\" 'with navigation
        myShell.Open strPath 'without navigation
        Do Until myShell.Windows.Count > ExplorerCount ' wait until new window is opened
            DoEvents
        Loop
 
        For Each myExplorerWindow In myShell.Windows
            On Error Resume Next
            If UCase(myExplorerWindow.Document.Folder.Self.Path) = UCase(strPath) Then
                Set FoundExplorerWindow = myExplorerWindow
                Exit For
            End If
            On Error GoTo 0
        Next
    
    End If
    
    FoundExplorerWindow.Width = 800
    FoundExplorerWindow.Height = 400
    ' Additionaly use .Top and .Left to reposition if you require
    FoundExplorerWindow.Visible = True
            
End Sub[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top