سؤال

I have a user form for text phrases and I want to save the entered phrases upon closing the user form. For some reason it does not work.

Here is my code:

Private Sub CancelButton_Click()

ActiveDocument.Variables("SPE 1") = UserForm1.TextBox1.Value
ActiveDocument.Variables("SPE 2") = UserForm1.TextBox2.Value
ActiveDocument.Variables("SPE 3") = UserForm1.TextBox3.Value
ActiveDocument.Variables("SPE 4") = UserForm1.TextBox4.Value
ActiveDocument.Variables("SPE 5") = UserForm1.TextBox5.Value
ActiveDocument.Variables("QAS 1") = UserForm1.TextBox6.Value
ActiveDocument.Variables("QAS 2") = UserForm1.TextBox7.Value
ActiveDocument.Variables("GPE 1") = UserForm1.TextBox8.Value
ActiveDocument.Variables("GPE 2") = UserForm1.TextBox9.Value

Unload UserForm1
End Sub

On initilization of user form I have the following code:

Sub UserForm1_Initialize()

UserForm1.TextBox1.Value = ActiveDocument.Variables("SPE 1").Value
UserForm1.TextBox2.Value = ActiveDocument.Variables("SPE 2").Value
UserForm1.TextBox3.Value = ActiveDocument.Variables("SPE 3").Value
UserForm1.TextBox4.Value = ActiveDocument.Variables("SPE 4").Value
UserForm1.TextBox5.Value = ActiveDocument.Variables("SPE 5").Value
UserForm1.TextBox6.Value = ActiveDocument.Variables("QAS 1").Value
UserForm1.TextBox7.Value = ActiveDocument.Variables("QAS 2").Value
UserForm1.TextBox8.Value = ActiveDocument.Variables("GPE 1").Value
UserForm1.TextBox9.Value = ActiveDocument.Variables("GPE 2").Value

End Sub

Does anyone know what's wrong with my code?

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

المحلول

How can you close a user form not using "Unload"?

You could use UserForm1.Hide

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top