VBA MSWord 2007-在第7行插入文本



我正在将数据从一个文档移动到另一个文档。我需要移动数据,并且已经将其作为字符串。我只是不知道如何把它放在另一个单词文档中。

以下人员正在获取文本。

'finds a range of text between the words "Purpose" and "Scope" and makes it strThePurpose
Application.ScreenUpdating = False
Selection.HomeKey wdStory
Selection.Find.Text = "Purpose"
blnFound = Selection.Find.Execute
If blnFound Then
    Selection.MoveLeft wdWord
    Set rng1 = Selection.Range
    Selection.Find.Text = "Scope" 'changed here 2014-18-04 from "7.0 Revisions:" to "Revisions:"
    blnFound = Selection.Find.Execute
    If blnFound Then
        Set rng2 = Selection.Range
        Set rngFound = ActiveDocument.Range(rng1.Start, rng2.Start)
        strThePurposeText = rngFound
        'MsgBox (strTheText)
    End If
End If

我只是不知道如何将它放在模板文件中特定行的word文档中。


已解决

似乎有效的答案:

Selection.GoTo What:=wdGoToLine, Which:=wdGoToFirst, Count:=7, Name:=""
Selection.TypeText Text:=strTheRefDocsText

解决得更好

一种更好更有效的方法是在单词中插入书签,并在书签处插入单词模板。

Selection.GoTo What:=wdGoToBookmark, Name:="bmBeginningOfDocument"
Selection.PasteAndFormat (wdPasteDefault)
Selection.GoTo What:=wdGoToBookmark, Name:="bmBeginningOfDocument"
Selection.PasteAndFormat (wdPasteDefault)

我使用了上面的代码作为如何到达该位置的更好主意。

最新更新