且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Word.Application中的光标位置获取文本

更新时间:2023-02-08 08:50:49

您可以使用Word-intern功能:

You could use the Word-intern functionality for that :
' connection to MS-Word
 objWordApplication = CreateObject("Word.Application")
 objWordApplication.Visible = False
 Dim objDoc As Word.Document
 objDoc = objWordApplication.Documents.Add(myFileName)
 objDoc.Protect(Word.WdProtectionType.wdNoProtection)
 objDoc.Activate()

 ' replace Text-elements
 With objWordApplication.Selection.Find
     .Text = "Date"
     .Replacement.Text = Now.ToString("dd.MM.yyyy")
     .Execute(Replace:=Word.WdReplace.wdReplaceAll)

      .Text = "Name"
     .Replacement.Text = myName
     .Execute(Replace:=Word.WdReplace.wdReplaceAll)

     .Text = "VorName"
     .Replacement.Text = myForeName
     .Execute(Replace:=Word.WdReplace.wdReplaceAll)

    End With





在此示例中关键字的每个外观将被我的应用程序中的字符串替换...



我希望它可以帮助你...



In this sample each appearence of the keyword will be replaced by a string from my application ...

I hope it helps you ...