سؤال

I have a userform with a button on it. I want the button to "refresh" the form, in other words I want the form to end, and then reopen.

The code below won't work because the form/macro has already ended, but I want the button to perform this task or similar.

sub command1.click()
end
userform1.show
end sub

I have checked and tried most or all the options I can choose from for a userform to "refresh". Is this even possible?

هل كانت مفيدة؟

المحلول

Here is a very simple way. Simply Re-Initialze the Userform using the UserForm_Initialize

Private Sub UserForm_Initialize()
    TextBox1.Text = "" '<~~ Just an Example

    '
    '~~> Put here the code to re-initialize the userform which will refresh it
    '
End Sub

Private Sub CommandButton1_Click()
    TextBox1.Text = "Sid"

    MsgBox "Re-Initialzing the Userform"

    UserForm_Initialize
End Sub

نصائح أخرى

Private Sub CommandButton1_Click()
    Unload Me
    UserForm1.Show
End Sub
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top