如何通过VBA获取MS Word文档中的文本框架

时间:2014-12-16 01:45:38

标签: vba word-vba

我有大型MS Word 2010文档,其中包含“框架”中的数据,至少这是我认为的。这是一个截图: Screenshot of frame

我试过这个来访问它:

Sub test()
Dim s As Shape
Dim i As Integer
Dim str As String
For Each s In ActiveDocument.Shapes
    i = i + 1
    If s.TextFrame.HasText Then
        Application.StatusBar = i
    End If
Next s
MsgBox ("done")
End Sub

但它不会让我在那里。我需要经历所有这些“框架”,但是,我甚至不确定它是什么,并将其转储到Excel中。有什么指针吗?我可以提取xml并解析它,但似乎有点矫枉过正。 (+我解析时不太好。)

1 个答案:

答案 0 :(得分:0)

我的* .rtf文件包含来自Oracle Reports的框架。试试我的宏。

Sub test()
Dim TabHourFrames() As Variant
numb_frames = ActiveDocument.Frames.Count
    ReDim TabHourFrames(1 To numb_frames)
    counter = numb_frames
    For i = 1 To counter
        Set myRange = ActiveDocument.Frames.Item(i).Range
        t = myRange.Text
        TabHourFrames(i) = t
    Next i
 Documents.Add DocumentType:=wdNewBlankDocument
        For q = 1 To counter
        last_par = ActiveDocument.Paragraphs.Count
        Set rngLastParagraph = ActiveDocument.Paragraphs(last_par).Range
            With rngLastParagraph
                    .InsertAfter Text:=TabHourFrames(q)
                    .InsertParagraphAfter
            End With
        Next q
ActiveDocument.Range(0, 0).Select
End Sub