我正在尝试找到一种简单的方法将“可变”数据获取到Word Docs中。
我有一个客户正在为各种过程提供单词模板。这将形成一个通往多个位置的文档,每个位置都有个性化信息。
这可以通过来自Excel的简单邮件合并来完成,但是还有其他问题:
DOC将包含带有主管联系信息的表。这是一般信息:姓名,电话联系人,电子邮件等。但是可能有1到5个联系人。我可以看到这意味着几行具有相同的键,这意味着我只想要一个副本。
是否有一种将数据合并到文档文本和表中的“简单”方法?这个想法是向客户提供“愚蠢的证明”解决方案,以便他们可以轻松更新模板和数据文件。
我也在考虑使用单词变量,但是一位消息人士说,文档中我会限制为15个变量。
任何想法都将不胜感激。还可以在此堆栈上查找以前的问题。
I'm trying to work out a simple way to get "variable" data into a Word docs.
I have a client who is supplying Word templates for various procedures. This would form a document that goes out to several locations, with personalized information for each location.
This could be done with a simple Mail Merge from Excel, but there are additional issues:
The doc will contain tables with supervisor contact information. It's the general info: Name, phone contacts, email, etc. But there could be 1 to 5 contacts. I could see that would mean several rows with the same key, meaning several copies where I only want one.
Is there an "easy" way to merge data into both document text and tables? The idea is to present the client with a "goof proof" solution so they can easily update the template and the data files.
I'm also looking at using Word variables, but one source said I'd be limited to 15 variable in a document.
Any ideas will be greatly appreciated. Also looking up previous questions on this stack.
发布评论
评论(1)
一种选择是在普通的“字母” Mailmerge主文档和宏来驱动过程中使用数据库字段。以下是这种方法的概述:
假设您有一个数据集,该数据集具有下属的FirstName,sunname,Employee ID和&amp&作业名称,每个记录都记录了他们经理的ID,其电子邮件地址也已记录。我们还假设MailMerge主文档与数据源保持在同一文件夹中。在这种情况下,您可以使用编码为:
{database \ d“ {filename \ p} /../ mm datasource.xlsx” \ s“ select [firstName],[firstName],[employee id],[雇员id],[[作业标题]来自[sheet1 $]其中[Manager ID] = {MergeField Manager_ID}订购[job Title]“ \ L” 15“ \ B” \ B“ 49” \ H}
在电子邮件中,其中'mm datasource.xlsx'是数据源文件名 - 如果您选择使用的话,它甚至可能是访问数据库文件名。如果MailMerge主文档不与数据源保存在同一文件夹中,则需要使用完整的路径&您需要替换所有“ {filename \ p} /../ mm datasource.xlsx”的所有“ {filename \ p} /../ mm datasource.xlsx”。文件名(加上包含双引号)。 \ l和\ b开关控制表格式,而\ h开关插入表标头行 - 请参阅:
上述示例的现场支撑对(即'{}')都是在文档本身中通过ctrl-f9(Mac上的CMD-F9)创建的;您不能简单地键入它们或复制&从这篇文章中粘贴他们。通过任何标准单词对话添加它们也不是实际的。田间构造中表示的空间都是必需的。
然后,要驱动流程,您可以使用一个宏,例如:
假设合并到电子邮件,但不是必需的。如果您希望输出转到Word文档,请更改
:
和删除:
注意:如果将上述宏重命名为'MailMergetOemail'(或'MailMerMergetOdoc'以将输出发送到文档),单击“发送电子邮件”(或“编辑单个文档”)按钮将截获合并,并且该过程将自动运行。这种方式拦截“发送电子邮件消息”(或“编辑单个文档”)过程的潜在缺点是,您不再选择在该阶段合并的记录。但是,您仍然可以通过“编辑收件人列表”工具实现相同的结果,并且可以通过更大的控制。
相反,如果您使用的是关系数据库或带有单独表的Excel工作簿,列出了每个分组标准(例如Manager_ID&电子邮件地址)以及每组一次发生一次的任何其他字段,则在正常的数据库字段中可以使用“字母”或“电子邮件” Mailmerge主文档,而无需宏。在这种情况下,将使用相同的数据库字段,但是MailMerge将仅连接到仅包含Manager_ID和名称的Excel工作表(或数据库表)。有关此方法的一些有效示例,请参见:
(其中第二个使用宏来应用一些其他格式)。
如果您想从第二个方法中保存每个小组的邮件输出作为单独的文档/pdf,请参见我的 mailmerge提示中的单个文件主题的将邮件输出发送到单个文件主题&技巧 page:
One option would be to use a DATABASE field in a normal ‘letter’ mailmerge main document and a macro to drive the process. Here is an outline of this approach:
Suppose you have a data set that has fields for the subordinates' Firstname, Surname, Employee ID, & Job Title, and that against each record is recorded their Manager's ID, whose email address is also recorded. Let's also assume the mailmerge main document is kept in the same folder as the data source. In that case, you could use a DATABASE field coded as:
{DATABASE \d "{FILENAME \p}/../MM datasource.xlsx" \s " SELECT [Firstname], [Surname], [Employee ID], [Job Title] FROM [Sheet1$] WHERE [Manager ID] = {MERGEFIELD Manager_ID} ORDER BY [Job Title] " \l "15" \b "49" \h}
in an email merge, where 'MM datasource.xlsx' is the data source filename - it could even be an Access database filename, if that's what you chose to use. If the mailmerge main document is NOT kept in the same folder as the data source, you'd need to replace all of "{FILENAME \p}/../MM datasource.xlsx" with the full path & filename (plus the encompassing double-quotes). The \l and \b switches control the table format, while the \h switch inserts a table header row - see: https://support.office.com/en-us/article/Field-codes-Database-field-04398159-a2c9-463f-bb59-558a87badcbc?ui=en-US&rs=en-US&ad=US
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this post. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required.
Then, to drive the process, you could use a macro like:
A merge to email is assumed, but not necessary. If you want the output to go to a Word document, change:
to:
and delete:
Note: If you rename the above macro as 'MailMergeToEmail' (or 'MailMergeToDoc' to send the output to a document), clicking on the 'Send Email Messages' (or 'Edit Individual Documents') button will intercept the merge and the process will run automatically. The potential disadvantage of intercepting the 'Send Email Messages' (or 'Edit Individual Documents') process this way is that you no longer get to choose which records to merge at that stage. However, you can still achieve the same outcome - and with greater control - via the 'Edit Recipient List' tools.
Conversely, if you're using a relational database or, an Excel workbook with a separate table listing each of the grouping criteria (e.g. the Manager_ID & email address) and any other fields that occur once per group, a DATABASE field in a normal ‘letter’ or 'email' mailmerge main document could be used without the need for a macro. In this case, the same DATABASE field would be used, but the mailmerge would be connected to the Excel worksheet (or database table) containing just the Manager_IDs and Names. For some working examples of this approach, see:
(the second of these uses a macro to apply some additional formatting).
If you'd like to have each group's mailmerge output from the second approach saved as a separate document/pdf, see the Send Mailmerge Output to Individual Files topic in my Mailmerge Tips & Tricks page: https://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html