将表单文本框值写入 Word 文档不起作用

发布于 2024-10-15 01:42:45 字数 1420 浏览 0 评论 0原文

我有一个用于文本短语的用户表单,我想在关闭用户表单时保存输入的短语。由于某种原因它不起作用。

这是我的代码:

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

在用户表单初始化时,我有以下代码:

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

有人知道我的代码有什么问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥琐帝 2024-10-22 01:42:45

如何关闭不使用“卸载”的用户表单?

您可以使用UserForm1.Hide

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

You could use UserForm1.Hide

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文