简体   繁体   English

在Microsoft Word中编辑附件模板中的内容

[英]Editing content in an attached template in Microsoft Word

I'm trying to create a macro that creates a Userform, which in turn creates a document based on a given template and the data input into the Userform. 我正在尝试创建一个创建Userform的宏,该宏又根据给定的模板和输入到Userform中的数据创建一个文档。

For example, the document might be a letter, with the content: 例如,文档可能是字母,其内容为:

"Dear @name, thank you for choosing us!" “亲爱的@name,感谢您选择我们!”

And I want to dynamically change the value @name with input from the Userform. 我想通过用户表单的输入来动态更改值@name。

I've tried experimenting with attaching Document Templates, but I don't know how to manipulate the content inside the template or create the document from the given template in the first place. 我尝试过附加文档模板的尝试,但是我不知道如何首先操作模板中的内容或从给定模板创建文档。

How do I go about doing this? 我该怎么做呢?

Thanks in advance. 提前致谢。

Create a DocVariable field for the name, eg "addressee", then you can simply set it like this (replace ActiveDocument with your document object): 为名称创建一个DocVariable字段,例如“ addressee”,然后可以像这样简单地设置它(用文档对象替换ActiveDocument ):

Dim docvar As Variable, doc As Document

Set doc = ActiveDocument
docvar = doc.Variables("addressee")
docvar.Value = "Mr.Smith"
doc.Fields.Update

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM