如何从word文件中提取所有word文档对象?
发布网友
发布时间:2022-03-17 02:48
我来回答
共1个回答
热心网友
时间:2022-03-17 04:17
代码不多,可是费了老劲。亲:一定要及时采纳哟。
Sub a()
'导出OLE里的文档
Dim strPath$, strTopic$, intCount%, intEnt%, OActdOC
strPath = ActiveDocument.Path & "\"
Set OActdOC = ActiveDocument
intCount = ActiveDocument.InlineShapes.Count
If intCount = 0 Then Exit Sub
For cx = 1 To intCount
With OActdOC.InlineShapes(cx).OLEFormat
If InStr(UCase(Format(.ClassType)), "WORD.DOCUMENT") <> 0 Then
With .Object
strTopic = Trim(.Paragraphs(1).Range.Text)
intEnt = InStr(strTopic, Chr(13)) - 1
strTopic = Left(strTopic, intEnt)
If Len(strTopic) > 200 Then strTopic = Left(strTopic, 30)
'如果出错,则是内嵌文件第一段里有不适用于文件名的字符,可用正则排除,本人不熟
.SaveAs strPath + strTopic
End With
End If
End With
Next
End Sub