简体   繁体   English

VBA Word 和使用 Excel 列作为查找和替换

[英]VBA Word and using Excel columns as a lookup and replace

I have a MS Word Doc that has the wrong words in it when it comes to me.我有一个 MS Word Doc,里面有错误的词。 I have a list of these words in Excel column A of book1, sheet1.我在 book1, sheet1 的 Excel 列 A 中有这些单词的列表。 I also have what the words should be column B of book1, sheet1.我也有的话应该是book1,sheet1的B列。

The list is about 300 words but the doc is only 50 words.列表大约有 300 个字,但文档只有 50 个字。

My thought is to copy and paste the text in the word doc with the VBA.我的想法是使用 VBA 复制并粘贴 word doc 中的文本。 Run a VBA to set Col A as a string and search the word doc.运行 VBA 将 Col A 设置为字符串并搜索单词 doc。 When found, replace it with Col B. At the end of the Doc set the next Col A as the string and do it again... until last line.找到后,将其替换为 Col B。在 Doc 的末尾,将下一个 Col A 设置为字符串并再次执行...直到最后一行。

I've work in Excel coding but I lost on this one.我在 Excel 编码方面工作过,但我输了。 As always any help is great.一如既往,任何帮助都很棒。

Robert罗伯特

You can use the vba dictionary object to build a dict with your Excel values.您可以使用vba 字典对象使用 Excel 值构建dict

Then, you can parse every value of your dictionary and Search & Replace the value in your Word document.然后,您可以解析字典的每个值并在 Word 文档中搜索和替换该值。 Need to test because it could be slow though.需要测试,因为它可能很慢。

Regards,问候,

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

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