|
Option Explicit
Sub test0() '导图片
Dim strFileName$, strPath$, n&, strDocName$, shp As Shape, inLineShp As InlineShape
Application.ScreenUpdating = False
strPath = ThisDocument.Path & "\"
strFileName = Dir(strPath & "*.doc*")
Do Until strFileName = ""
If strFileName <> ThisDocument.Name Then
With Documents.Open(strPath & strFileName)
For Each shp In .Shapes
If shp.Type = msoPicture Then shp.ConvertToInlineShape
Next
strDocName = Left(strFileName, InStrRev(strFileName, ".") - 1)
n = 0
For Each inLineShp In .InlineShapes
n = n + 1
Call ToSaveImg(inLineShp, strPath & strDocName & "-" & n & ".png")
Next
.Close False
End With
End If
strFileName = Dir
Loop
Application.ScreenUpdating = True
Beep
End Sub
Sub test1() '合并文档
Dim strFileName$, strPath$, strSaveName$
Application.ScreenUpdating = False
strPath = ThisDocument.Path & "\"
strFileName = Dir(strPath & "*.doc*")
With Documents.Add
strSaveName = strPath & "合并"
Do Until strFileName = ""
If strFileName <> ThisDocument.Name Then
With Documents.Open(strPath & strFileName)
.Content.Copy
.Close False
End With
Selection.Paste
End If
strFileName = Dir
Loop
.SaveAs strSaveName
.Close
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
|
评分
-
4
查看全部评分
-
|