简体   繁体   English

使用Ms-Excel中的数据通过VBA填充Ms-Word中的预定义模板

[英]Using data from Ms-Excel to fill a pre-defined template in Ms-Word through VBA

Summary : I have to fill reports in excel and then manually copy the same in doc as required by my seniors to track bugs in different applications. 摘要 :我必须在excel中填写报告,然后按照我的上级要求将其手动复制到doc中,以跟踪不同应用程序中的错误。 The excel and doc report is different for every application. 每个应用程序的excel和doc报告都不同。 So I want to save work as I fill a excel and export it in the agreed template in word. 所以我想保存工作并填写Excel并将其导出到Word中约定的模板中。

Problem : I am trying to write a macro which will search some variables in pre-defined template (doc) and replace these variables with data from excel. 问题 :我正在尝试编写一个宏,该宏将搜索预定义模板(doc)中的一些变量,并将这些变量替换为来自excel的数据。 The variables are nothing but some text like <-AppName->, <-AppID-> (self created). 这些变量不过是一些文本,例如<-AppName->,<-AppID->(自行创建)。 Now there is a twist as there is one sheet in excel which has issues marked as high medium and low. 现在有一个转折,因为excel中有一张纸被标记为高中和低。 I want to export this list to same doc as three different tables marked as high medium and low. 我想将此列表导出为标记为高中和低的三个不同表的同一文档。

Question : How to populate variables (as above) in doc using the data from excel via VBA? 问题 :如何通过VBA使用Excel中的数据填充文档中的变量(如上所述)? If at all I can populate variables how do I manage to export the data from excel to doc in three different tables since it will have multiple lines. 如果完全可以填充变量,我将如何在三个不同的表中将数据从excel导出到doc,因为它将有多行。

Thanks in advance. 提前致谢。

I haven't gone in-depth to look at this but I don't see why it wouldn't work. 我没有深入研究这个问题,但是我不明白为什么它不起作用。

1) Set up your library references in your VBA project so you can access Word's VBA API. 1)在VBA项目中设置您的库引用,以便您可以访问Word的VBA API。
2) In Excel VBA method, set up an array of your search/replacements. 2)在Excel VBA方法中,设置一个搜索/替换数组。
3) In that same module, open the Word file(s) and replace the variables. 3)在同一模块中,打开Word文件并替换变量。 Like I said I haven't fiddled around with the API so I can't say if you can do this easily...but also check this out . 就像我说的那样,我还没有摆弄API,所以我不能说您是否可以轻松地做到这一点...还要检查一下
4) Save the word documents as new files, close them. 4)将Word文档另存为新文件,然后将其关闭。

I'm not sure what you mean "three different tables" but once you figure out how to find/replace that part should be a breeze. 我不确定您的意思是“三个不同的表”,但是一旦您弄清楚如何查找/替换该零件,应该很容易。

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

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