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!

Resize an Application Window

Status
Not open for further replies.

Sparky1157

Programmer
Aug 19, 2016
30
US
I've tried a couple of methods for resizing an application window, but neither of these options work - they result in 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

Could someone please offer a solution to this issue?

 
Hey, Sparky (love that name, reminiscent of Big John and Sparky from the 50s)

Don't have a solution, just an observation.

You don't resize an Application object. There is an Application Object Property for the Window that you need to find. First you must instantiate an application object using CreatObject or GetObject.

However, the Attachmate VB Editor is pretty bland when it comes to editing features. I almost always coded in Excel VBA since my criteria and results came from/went to Excel for further analysis and distribution. Excel VBA has a Watch Window when one can DISCOVER the properties so mentioned.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thanks, Skip!

Hey, Skip is a pretty cool name as well! I remember the Skip & Bob show from the early 60s.... Had my picture taken with Bob at a breakfast celebration way back then!

I'll have to take a look - I do create the object using CreateObject:

Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "explorer"

Here's to digging a little deeper....
 
so is WshShell the application object of interest?

If so, then regarding method 2:
Code:
With WshShell
.WindowState = [s]wdWindowStateNormal[/s]
.Windows(1).Resize Width:=InchesToPoints(7), Height:=InchesToPoints(6)
wdWindowStateNormal Appears to be a Microsoft Word constant. You might need to find the numeric value of this constant to use.

I also added a property .Windows(1) meaning for the Application object the Windows collection qualified to the first in the collection. Just a guess that you might care to try.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thanks, Skip! Unfortunately, even that continues to give me a compile error.
 
This brings up Windows File Explorer. Is that what you want?

Code:
Sub ResizeWindow()
    Dim WshShell As Object
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "explorer"
End Sub

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Doing some snooping using the above code and WsShell has only 2 properties: CurrentDirectory (String) and SpecialFolders (Collection)

There is no WINDOWS property.

At this point, you might be better off in the VBScript forum, cuz your code has nothing to do with Attachmate at this juncture.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thanks to Skip's advice I went to the VB Script forum and received some additional support from them. However, it appears that the Attachmate VB Editor contains an older version of VB, or at the very least a subset of what's available in the Excel VB Editor. I needed to use the Excel VB Editor to compile and run the following macro - in the Attachmate VB Editor it won't compile.

--------------------------------------------
'
' Establish Sleep subroutine from kernel32.dll file.
'
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Auto_Open()
'
' Set up system variables.
'
Dim myShell As Object
Dim myExplorerWindow As Object
Dim iCnt As Integer
Dim WshShell As Object
'
' Establish location of comment files.
'
Dim FolderPath As String
FolderPath = "G:\Desktop Folder"
'
' Load Windows Explorer.
'
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "explorer"
Sleep 3000 ' Pause for 3 seconds.
' WshShell.AppActivate "Explorer"
'
' Set explorer to folder path.
'
WshShell.SendKeys ("%d")
WshShell.SendKeys (FolderPath)
WshShell.SendKeys ("{Enter}")
Sleep 2000 ' Pause for 2 seconds.
'
' Turn off navigation pane.
'
WshShell.SendKeys ("%d")
Sleep 100 ' Pause for 1/10 of a second.
WshShell.SendKeys ("{Tab}")
Sleep 100 ' Pause for 1/10 of a second.
WshShell.SendKeys ("{Tab}")
Sleep 100 ' Pause for 1/10 of a second.
WshShell.SendKeys ("{Down}")
Sleep 100 ' Pause for 1/10 of a second.
WshShell.SendKeys ("l")
Sleep 100 ' Pause for 1/10 of a second.
WshShell.SendKeys ("n")
'
' Establish application variable.
'
Set myShell = CreateObject("Shell.Application")
'
' Select Active Windows Explorer window.
'
For Each myExplorerWindow In myShell.Windows
On Error Resume Next
iCnt = iCnt + 1
If iCnt = myShell.Windows.Count Then
If myExplorerWindow.Parent.Name = "Windows Explorer" Then
'
' Resize and relocate Windows Explorer window.
'
myExplorerWindow.Width = 280
myExplorerWindow.Height = 820
myExplorerWindow.Top = 150
myExplorerWindow.Left = 1265
' myExplorerWindow.Visible = True
End If
End If
On Error GoTo 0
Next
'
' Quit Excel
'
Application.Quit
End Sub
--------------------------------------------

Thanks so much to everyone who assisted in this process! Very much appreciated.
 
I realize that some users need or want to run macros from the Extra application where they are performing their work.

However, as a screen scraper, I ran EVERYTHING from Excel VBA and had great success.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Absolutely, Skip!

Also, if you would like to set up an icon on the desktop in order to run the macro and disable the splash screen, then exit Excel automatically, this can be accomplished as well. You just need to know where the EXCEL.EXE file is located. The /e flag prevents the splash screen from displaying. So the icon on my desktop contains the following information:

"C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE" /e "G:\Macros\Open Client Relations Desktop Folder.xlsm"

And, as indicated above, the macro contains the line Application.Quit, which exits Excel after executing the macro.
 
How about a .bat file to open a specific Excel workbook. In that workbook's Workbook_Open event, run your macro, that would include closing that instance of Excel.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Yes, thanks, Skip!

As usual, more than one way to skin a cat, so to speak!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top