【问题标题】:How to copy textbox value in a word document into a textbox in a different word document with VBA (MS Word 2003)如何使用 VBA 将 word 文档中的文本框值复制到不同 word 文档中的文本框(MS Word 2003)
【发布时间】:2024-01-19 07:34:01
【问题描述】:

希望是一个简单的问题。

我有两个 word 文档(MS Word 2003),每个文档都有一个文本框对象。按下命令按钮后,我希望一个文档(“Reference_Text.docx”)文本框中的文本进入另一个文档的文本框。

下面显示了我在按下命令按钮时尝试在事件中使用的代码。我正在尝试使用 Reference_Text.docx 文件中的“txtLocation_Analysis_1”中的文本填充文本框 (txtLocation_Analysis)。

Dim objWord As Word.Application 
Dim wd As Word.Document
Set wd = objWord.Documents.Open("C:\Users\Tim\Desktop\Reference_Text.docx")

ThisDocument.txtLocation_Analysis.Text = '(Want to call a "txtLocation_Analysis_1.text" from wd document)

让我知道这是否有意义 - 如果可以提供任何帮助,请:)

【问题讨论】:

  • 第三段的措辞不是很清楚。你到底想要什么?
  • 我已经重做了描述,如果有帮助请告诉我?

标签: vba ms-word


【解决方案1】:

你试过了吗

ThisDocument.txtLocation_Analysis.Text = "txtLocation_Analysis_1.text" ' A

ThisDocument.txtLocation_Analysis.Text = wd.txtLocation_Analysis_1.Text ' B

抱歉,我仍然不清楚措辞,但我认为您希望 (A) 字符串“txtLocation_Analysis_1.text”或 (B) 您打开的文档中另一个文本框的内容出现在文本框中本文档。​​

【讨论】: