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





沒有留言:

張貼留言

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

 指數變化(2025.08.29) 開始透過AI做整理 上周焦點: 8/19(二)   美國房屋開工率 5%月增  美國建築許可月增率 月增2.8% 8/20(三)   美國房貸綜合指數 月減0.5%  美國30年期房貸利率 6.69%  美國15年期房貸利率 5.8~5.71%...