简体   繁体   English

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

[英]How to get text frames in MS Word document via VBA

I have large MS Word 2010 document that consists of data in "frames" at least that is what I believe it is. 我有一个很大的MS Word 2010文档,至少由“框架”中的数据组成,这就是我认为的事实。 Here's a screenshot: 这是屏幕截图: 框架截图

I tried this to access it: 我试图这样做来访问它:

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

But it wouldn't get me there. 但这不会把我带到那里。 I need to go through all these "frames", but again, I'm not even sure what it is, and dump it into Excel. 我需要遍历所有这些“框架”,但是同样,我什至不知道它是什么,然后将其转储到Excel中。 Any pointers? 有指针吗? I can extract the xml and parse it, but seems a bit overkill. 我可以提取xml并对其进行解析,但是似乎有些过分了。 (+ I'm not so good with parsing yet). (+我还不太擅长解析)。

I have *.rtf file with frames from Oracle Reports. 我有带有Oracle Reports框架的* .rtf文件。 Try my macro. 试试我的宏。

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

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

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