|
Option Explicit
Sub test()
Dim strFileName$, strSavePath$, strPath$, inLineShp As InlineShape
Application.ScreenUpdating = False
strPath = ActiveDocument.Path & "\"
strSavePath = strPath & "图片88\"
If Dir(strSavePath, vbDirectory) = "" Then MkDir strSavePath
With ActiveDocument
For Each inLineShp In .InlineShapes
inLineShp.Select
With Selection
.Collapse
.MoveDown unit:=wdLine
.MoveEndUntil vbCr
strFileName = .Range.Text
ToSaveImg inLineShp, strSavePath & strFileName & ".png"
End With
Next
End With
Application.ScreenUpdating = True
Beep
End Sub
Function ToSaveImg(ByVal objShp As InlineShape, ByVal strFullPath As String)
Const TAG_S = "<pkg:binaryData>"
Const TAGE = "</pkg:binaryData>"
Dim objNode As Object, IngStart&, IngEnd&, bytImage() As Byte, strXML$, rngShp As Range
strXML = objShp.Range.WordOpenXML
IngStart = InStr(strXML, TAG_S)
If IngStart = 0 Then
MsgBox "没有图片数据"
Exit Function
Else
IngStart = IngStart + Len(TAG_S)
IngEnd = InStr(IngStart, strXML, TAGE)
strXML = Mid$(strXML, IngStart, IngEnd - IngStart)
Set objNode = CreateObject("MSXML2.DOMDocument").createELement("b64")
objNode.DataType = "bin.base64"
objNode.Text = strXML
bytImage = objNode.nodeTypedValue
Open strFullPath For Binary As #1
Put #1, 1, bytImage
Close #1
Set objNode = Nothing
End If
End Function
|
评分
-
2
查看全部评分
-
|