2025年4月30日 星期三

VBA:控制表單的位置(APPLICATION應用)

 沒寫控制,表單顯示時都出現在螢幕正中央,實在很煩,小編就改了一下,當作磨練。

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





沒有留言:

張貼留言

指數變化(2026.6.18) 開始透過AI做整理

 指數變化(2026.6.18) 開始透過AI做整理 一、上周焦點: 6/17 美國聯邦基金利率 更新:20260603 我賭最近一次FED會議後不升息:我瞎貓矇到的。 確定不升息,但作風改了,也打算針對FED過去方式作改革,也不提供前瞻指引了。 我覺得市場解讀很多層,反應時間點...