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

时间:2014-04-18 17:49:44

标签: vba text insert ms-word line

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

以下是获取文字。

'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)

1 个答案:

答案 0 :(得分:0)

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

我使用上面的代码更好地了解如何到达该位置。