繁体   English   中英

如何将文本从Word文档转换为另一个Word文档

[英]How to get text from a Word document into another Word Document

我有两个Word文档,每个文档都包含一个单词。 我有第三个文档,需要从两个文档中提取每个单词,并使用替换功能编辑文档中的所有超链接。 如果我在函数中输入字符串,则replace函数有效,但是当尝试从文档中拉出两个单词时,替换函数不起作用

Public Sub Document_Open()
    Dim x As Document

    Set newSource = Application.Documents.Open("\\t1dc\Everyone\Ben\ns.docx", ReadOnly:=True, Visible:=False)
    Set oldSource = Application.Documents.Open("\\t1dc\Everyone\Ben\os.docx", ReadOnly:=True, Visible:=False)

    Dim newServer As Range
    Set newServer = newSource.Content

    'Test using message box
    MsgBox newServer

    Dim oldServer As Range
    Set oldServer = oldSource.Content

    'Test using message box
    MsgBox oldServer

    For Each h In ActiveDocument.Hyperlinks
           h.Address = Replace(h.Address, oldServer.Text, newServer.Text)
           MsgBox h.Address
    Next

    newSource.Close
    oldSource.Close

    Set x = Nothing
End Sub

检查oldServer和newServer的长度,因为您还将输入行尾的\\r

是的,谢谢!

从字符串末尾删除并正常工作

昏暗的oldS作为字符串oldS = Left(oldServer.Text,Len(oldServer.Text)-1)

暂无
暂无

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

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