×
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!
  • Students Click Here

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

Students Click Here

Jobs

Trying to Resize Application Window
3

Trying to Resize Application Window

Trying to Resize Application Window

(OP)
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!

RE: Trying to Resize Application Window

Method 1, I'm not familiar with the moveTo method of the wscript shell

Method 2, is VBA.

How are you executing your vbscript?

RE: Trying to Resize Application Window

In #2, is it VBA, in what application, what application you try to resize?

combo

RE: Trying to Resize Application Window

(OP)
I'm trying to resize a Windows Explorer window.

RE: Trying to Resize Application Window

That didn't answer combo's question, or mine.

RE: Trying to Resize Application Window

(OP)
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!

RE: Trying to Resize Application Window

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.

RE: Trying to Resize Application Window

(OP)
okay - well, thank you for your attention to this matter!

RE: Trying to Resize Application Window

Quote:

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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Trying to Resize Application Window

3
>I don't see any way to resize a Windows Explorer window using any native program including vbscript

Of course you can ... winky smile

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

CODE

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
            ' Additinaly use .Top and .Left to reposition if you require
            myExplorerWindow.Visible = True
        End If
        On Error GoTo 0
    Next
End Sub 

Unfortunately not familiar with current versions of Attachmate, so can't give an example of directly integrating this code with it.

RE: Trying to Resize Application Window

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 = "Windows Explorer" Then 

Big star for that, strongm.

Sparky1157: If you can't get this code working, post what you have tried.

RE: Trying to Resize Application Window

(OP)
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.

RE: Trying to Resize Application Window

(OP)
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.

RE: Trying to Resize Application Window

This rather sugests to me that Attachmate Extra is NOT a vbScript host

RE: Trying to Resize Application Window

>My only tweak was to change the IF statement to

Yes, Microsoft changed the Name for Windows 10.

RE: Trying to Resize Application Window

(OP)
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

RE: Trying to Resize Application Window

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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Trying to Resize Application Window

(OP)
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....

RE: Trying to Resize Application 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

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 

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!

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