[英]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.