AW: Buttons auf Userform beim Laden verschieben?!?
27.04.2007 01:05:00
Erich
Hallo Till,
wenn es die beiden Application-Eigenschaften in Excel 2000 nicht gäbe,
würde der Code dort gar nicht laufen, sondern einen Kompilierungsfehler ergeben.
Der Code positioniert aber nur anders als gewünscht.
Ich habe mal die vorkommenden Werte ausgeben lassen (aus deinem Code in den Spalten 2 und 3,
aus meinem Code-Vorschlag - unter Excel XP - in den Spalten 5 und 6).
Aus den Werten in den Spalten 2 und 3 lässt sich ersehen,
dass der Button zu weit rechts unten positioniert wird.
Du kannst ja mal die Werte mit denen in deinem Excel 2003 vergleichen:
Tabelle1
| A | B | C | D | E | F |
2 | | Height | Width | | Height | Width |
3 | GetSystemMetrics(SM_CYSCREEN) | 768 | 1024 | | 768 | 1024 |
4 | Me.Height | 576 | 768 | | 574 | 766 |
5 | CommandButton5.Height | 24 | 100 | | 24 | 100 |
6 | CommandButton5.Top | 542 | 724 | | 520 | 650 |
7 | Application.Height | 582 | 774 | | 582 | 774 |
8 | iTop | 532 | 724 | | | |
Hier der Code dazu:
Private Sub xUserForm_activate()
Dim zz As Long
Dim iTop As Integer, iLeft As Integer
' On Error Resume Next
'Positionierung der Userform
Me.Left = 0
Me.Top = 0
Me.Height = GetSystemMetrics(SM_CYSCREEN) * 0.75
Me.Width = GetSystemMetrics(SM_CXSCREEN) * 0.75
'Positionierung der Buttons
iTop = Application.Height - 50
iLeft = Application.Width - 50
'Stop Button
CommandButton5.Top = iTop + 10
CommandButton5.Left = iLeft
With Sheets(1)
zz = 2
zz = zz + 1: .Cells(zz, 1) = "GetSystemMetrics(SM_CYSCREEN)"
zz = zz + 1: .Cells(zz, 1) = "Me.Height"
zz = zz + 1: .Cells(zz, 1) = "CommandButton5.Height"
zz = zz + 1: .Cells(zz, 1) = "CommandButton5.Top"
zz = zz + 1: .Cells(zz, 1) = "Application.Height"
zz = zz + 1: .Cells(zz, 1) = "iTop"
zz = 2
zz = zz + 1: .Cells(zz, 2) = GetSystemMetrics(SM_CYSCREEN)
zz = zz + 1: .Cells(zz, 2) = Me.Height
zz = zz + 1: .Cells(zz, 2) = CommandButton5.Height
zz = zz + 1: .Cells(zz, 2) = CommandButton5.Top
zz = zz + 1: .Cells(zz, 2) = Application.Height
zz = zz + 1: .Cells(zz, 2) = iTop
zz = 2
zz = zz + 1: .Cells(zz, 3) = GetSystemMetrics(SM_CXSCREEN)
zz = zz + 1: .Cells(zz, 3) = Me.Width
zz = zz + 1: .Cells(zz, 3) = CommandButton5.Width
zz = zz + 1: .Cells(zz, 3) = CommandButton5.Left
zz = zz + 1: .Cells(zz, 3) = Application.Width
zz = zz + 1: .Cells(zz, 3) = iLeft
End With
End Sub
Private Sub UserForm_activate()
Dim zz As Long
Dim iTop As Integer, iLeft As Integer
' On Error Resume Next
'Positionierung der Userform
Me.Left = 1
Me.Top = 1
Me.Height = GetSystemMetrics(SM_CYSCREEN) * 0.75 - 2
Me.Width = GetSystemMetrics(SM_CXSCREEN) * 0.75 - 2
'Positionierung der Buttons
iTop = Me.Height - 100
iLeft = Me.Width - 100
'Stop Button
CommandButton5.Top = Me.Height - CommandButton5.Height - 30
CommandButton5.Left = Me.Width - CommandButton5.Width - 16
With Sheets(1)
zz = 2
zz = zz + 1: .Cells(zz, 5) = GetSystemMetrics(SM_CYSCREEN)
zz = zz + 1: .Cells(zz, 5) = Me.Height
zz = zz + 1: .Cells(zz, 5) = CommandButton5.Height
zz = zz + 1: .Cells(zz, 5) = CommandButton5.Top
zz = zz + 1: .Cells(zz, 5) = Application.Height
zz = 2
zz = zz + 1: .Cells(zz, 6) = GetSystemMetrics(SM_CXSCREEN)
zz = zz + 1: .Cells(zz, 6) = Me.Width
zz = zz + 1: .Cells(zz, 6) = CommandButton5.Width
zz = zz + 1: .Cells(zz, 6) = CommandButton5.Left
zz = zz + 1: .Cells(zz, 6) = Application.Width
End With
End Sub
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort