简体   繁体   English

如何使用 Excel VBA 或任何建议的程序编辑 Word 文件?

[英]How to edit a Word file using Excel VBA or any suggested programme?

I'm wondering how could I edit a particular word or phrase in the word document by writing some Excel VBA codes?我想知道如何通过编写一些 Excel VBA 代码来编辑 Word 文档中的特定单词或短语? Or, any other recommended program to do so?或者,还有其他推荐的程序可以这样做吗?

For example, my Word document is like the following,比如我的Word文档是这样的,

Dear FRIEND,亲爱的朋友,
## Greeting on DATE ## ##在日期问候##

How are you?你好吗? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Cheers, Kevin干杯,凯文

My goal is to search for FRIEND and then replace a name that I may want to use like Peter , and then search for DATE and replace a date say 28th Sept, 2017 .我的目标是搜索FRIEND然后替换一个我可能想使用的名字,比如Peter ,然后搜索DATE并替换一个日期,比如28th Sept, 2017

Hope someone could help me with this!希望有人能帮我解决这个问题! Many thanks!非常感谢!
Cheers, Kevin干杯,凯文

You could also use some bookmarks:您还可以使用一些书签:

Instead of replacing some text by something else you could place a bookmark named Friend or Date in the choosen place and then write on the bookmarks like this您可以在所选位置放置一个名为“朋友”或“日期”的书签,然后像这样写在书签上,而不是用其他东西替换某些文本

ThisDocument.Bookmarks("NAME_OF_THE_BOOKMARK").Range.Text ="your text"

To place a bookmark you have to click on the selected area and then go on Insert->Bookmarks要放置书签,您必须单击所选区域,然后继续插入->书签

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

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