召回用户表格位置

问题描述 投票:0回答:1

无法在互联网上找到许多示例,而在论坛上关于保存用户表单以重新加载的位置绝对没有任何内容。

此宏可以在几个网站上看到:

Copy to clipboard
Option Explicit

Private Sub UserForm_Initialize()
If GetSetting("My Settings Folder", Me.Name, "Left Position") = "" _
    And GetSetting("My Settings Folder", Me.Name, "Top Position") = "" Then
    Me.StartUpPosition = 1 ' CenterOwner
Else
    Me.Left = GetSetting("My Settings Folder", Me.Name, "Left Position")
    Me.Top = GetSetting("My Settings Folder", Me.Name, "Top Position")
End If

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    SaveSetting "My Settings Folder", Me.Name, "Left Position", Me.Left
    SaveSetting "My Settings Folder", Me.Name, "Top Position", Me.Top
End Sub

但是...在这里不起作用。

我在做什么错?

forms position registry
1个回答
0
投票

答案非常明显...除了我忽略了它,而且互联网上的一些样本没有提到这一点:

用户窗体的StartUpPosition必须设置为“ 0”(零)。这是编辑后的宏:

Private Sub UserForm_Initialize()
    If GetSetting("My Settings Folder", Me.Name, "Left Position") = "" _
        And GetSetting("My Settings Folder", Me.Name, "Top Position") = "" Then
        Me.StartUpPosition = 1 ' CenterOwner
    Else
        Me.StartUpPosition = 0
        Me.Left = GetSetting("My Settings Folder", Me.Name, "Left Position")
        Me.Top = GetSetting("My Settings Folder", Me.Name, "Top Position")
    End If

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    SaveSetting "My Settings Folder", Me.Name, "Left Position", Me.Left
    SaveSetting "My Settings Folder", Me.Name, "Top Position", Me.Top
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.