沒寫控制,表單顯示時都出現在螢幕正中央,實在很煩,小編就改了一下,當作磨練。
VBA:
使用,做一個表單,放進去後,調整LEFT跟TOP,勘你想要放那 XD。
Private Sub UserForm_Activate()
Call PositionUserFormRelativeToExcel
End Sub
Sub PositionUserFormRelativeToExcel()
Dim excelLeft As Single
Dim excelTop As Single
Dim excelWidth As Single
Dim excelHeight As Single
' 獲取 Excel 視窗的位置和大小
excelLeft = Application.Left
excelTop = Application.Top
excelWidth = Application.Width
excelHeight = Application.Height
' 設定 UserForm1 的位置,使其位於 Excel 視窗的右側
With Me
.StartUpPosition = 0 ' 設定為手動位置
.Left = excelLeft + excelWidth - .Width - 10 ' 設定左邊位置,使其位於 Excel 視窗的右側
.Top = excelTop + (excelHeight - .Height) / 2 ' 設定頂部位置,使其在垂直方向居中
If Me.Visible = True Then
Else
.Show 0
End If
End With
End Sub