ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Arranging Windows (https://www.excelbanter.com/excel-programming/326477-arranging-windows.html)

J Streger

Arranging Windows
 
I have a piece of code that creates a second window. I noticed that on only
one of the windows are the VBA control buttons active. When I arrange the
windows programatically using Application.Windows.Arrange to arrange the
windows horizontally, the window with the active buttons always is on the
bottom. Is there any way I can make sure that it's on top instead? I'm using
Excel 2000. Thank you.
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003


Dave Peterson[_5_]

Arranging Windows
 
Do you create the second window?

If you do, maybe you could keep track of what the activewindow was when you
started. And it sure looks like the activewindow ends up at the top when I
arrange them horizontally.

Option Explicit
Sub testme01()
Dim myWindow As Window
Set myWindow = ActiveWindow

Application.ScreenUpdating = False
myWindow.NewWindow
myWindow.Activate
Windows.Arrange arrangestyle:=xlArrangeStyleHorizontal, _
ActiveWorkbook:=True

Application.ScreenUpdating = True
End Sub

Worked for me.


J Streger wrote:

I have a piece of code that creates a second window. I noticed that on only
one of the windows are the VBA control buttons active. When I arrange the
windows programatically using Application.Windows.Arrange to arrange the
windows horizontally, the window with the active buttons always is on the
bottom. Is there any way I can make sure that it's on top instead? I'm using
Excel 2000. Thank you.
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003


--

Dave Peterson

keepITcool

Arranging Windows
 

window 1 is always the activewindow..
also going thru the windows collection by number
will not produce the desired results..

so i tried following, I dont know if it is the 'proper' approach,
but it does seem to do the trick... :)

Get the names..
Sort them,
Activate in reverse order..
and then finally use Arrange

Produces the "first" window on top.




Sub ArrangeWindowsByName()
' 31-3-2005 by keepITcool

Dim i&, aNames
Application.ScreenUpdating = False
With ActiveWorkbook.Windows
'Store the names of the windows
ReDim aNames(1 To .Count)
For i = 1 To .Count
aNames(i) = .Item(i).Caption
Next
'Sort the names array
qSort aNames
'Activate in reverse order
For i = .Count To 1 Step -1
With .Item(aNames(i))
If .Visible Then .Activate
End With
Next
.Arrange ArrangeStyle:=xlHorizontal
End With
Application.ScreenUpdating = True

End Sub

Sub qSort(v, Optional n& = True, Optional m& = True)
Dim i&, j&, p, t
If n = True Then n = LBound(v): If m = True Then m = UBound(v)
i = n: j = m: p = v((n + m) \ 2)
While (i <= j)
While (v(i) < p And i < m): i = i + 1: Wend
While (v(j) p And j n): j = j - 1: Wend
If (i <= j) Then
t = v(i): v(i) = v(j): v(j) = t
i = i + 1: j = j - 1
End If
Wend
If (n < j) Then qSort v, n, j
If (i < m) Then qSort v, i, m
End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


J Streger wrote :

I have a piece of code that creates a second window. I noticed that
on only one of the windows are the VBA control buttons active. When I
arrange the windows programatically using Application.Windows.Arrange
to arrange the windows horizontally, the window with the active
buttons always is on the bottom. Is there any way I can make sure
that it's on top instead? I'm using Excel 2000. Thank you.



All times are GMT +1. The time now is 11:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com