繁体   English   中英

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

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

我有一个很大的MS Word 2010文档,至少由“框架”中的数据组成,这就是我认为的事实。 这是屏幕截图: 框架截图

我试图这样做来访问它:

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并对其进行解析,但是似乎有些过分了。 (+我还不太擅长解析)。

我有带有Oracle Reports框架的* .rtf文件。 试试我的宏。

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