vb6替换WinWord标头中的文本 [英] vb6 replacing text in WinWord Header
问题描述
大家好,
请有人帮忙。我有一个客户端使用VB6构建的应用程序。在不同阶段,这将运行Word文档模板,并使用数据库中的信息替换各种字段(这只是背景信息)。
他们最近对标题进行了更改,所以现在标题包含需要替换的信息。
我搜索过CodeProject,以及网上相当广泛但无法找到有效的解决方案...
我能想出的最好的是下面的代码(它不会崩溃,但它找不到文本,即使它在文件中)...
Hi all,
Please can someone help. I have a client using a VB6 built app. At various stages this runs through a Word Document Template and replaces various fields with info from a Database (this is just background info).
They have recently made changes to the header, so now the header contains information that needs to be replaced.
I have searched CodeProject, as well as quite extensively on the net and can't find a valid solution...
The best I can come up with is the below code (which doesn't crash, but it doesn't find the text, even though it IS in the file)...
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Select
Do While ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Find.Execute("<User_Branch_Tel>") = True
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Cut
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).InsertAfter "Test"
Loop
推荐答案
大家好,
经过多次坚持,我找到了答案:
Hi everyone,
After lots of persistence I found the answer:
Set Range = NewApp.ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
Do While Range.Find.Execute("TextToSearchFor") = True
Range.Cut
Range.InsertAfter "TextToReplace"
Loop
谢谢......
Thanks...
这篇关于vb6替换WinWord标头中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!