如何从章节和子章节中提取图片

时间:2019-07-11 12:23:09

标签: vba ms-word

我面临着从Word文档提取图片的问题。

通过这段代码,我成功地从第一章中选择并提取了图片:

With Selection
.Collapse
Dim curRange As Range
Set curRange = .Range
.Extend
.GoTo What:=wdGoToHeading, which:=wdGoToNext
If .Range = curRange Then
    .EndKey Unit:=wdStory
End If
.ExtendMode = False
Selection.copy
End With

复制部分在这里

fileName = Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1) 
fileName = Replace(fileName, " ", "_")
folderName = CreateObject("WScript.Shell").SpecialFolders.Item("Desktop")

If Selection.InlineShapes.Count > 0 Then

Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True


Set WordDoc = WordApp.Documents.Add
WordDoc.Content.Paste

For i = WordDoc.Shapes.Count To 1 Step -1
    WordDoc.Shapes(i).Delete
Next i

Dim fso As Object
Dim fldrpath As String
Set fso = CreateObject("scripting.filesystemobject")

fldrpath = folderName & "\imagesSpec\"
If Not fso.folderexists(fldrpath) Then
    fso.createfolder (fldrpath)
End If

WordDoc.SaveAs2 fileName:=folderName & "\imagesSpec\" & fileName & ".html", FileFormat:=wdFormatFilteredHTML
WordApp.Quit

由于经过html过滤,我从另一个Word文档中复制的选择中得到了图片

我现在要做的是在子章节中提取(实际上是:选择)(如果有一个或多个)

示例:我提取第1章)的图片,我想获得1.1),1.2),1.2.1)...

有什么想法吗?谢谢

0 个答案:

没有答案