问题描述
我有一个简单的要求,将Word Doc中嵌入的MS-Office图形对象保存为图像文件.以下代码可用于从Powerpoint提取图像.但是,如果我将ActivePresentation修改为ActiveDocument,则不适用于MS-Word.导出方法不适用于形状对象.有什么想法吗?
I have a simple requirement to save MS-Office Drawing Objects embedded within a Word Doc to image files. The following code worked for image extraction from Powerpoint. However it does not work for MS-Word if I modify the ActivePresentation to ActiveDocument. The Export method was not available for shape object. Any ideas?
Dim oPPTShap as Shape
For k = 1 To .Slides(intSlide).Shapes.Count
Set oPPTShape = ActivePresentation.Slides(intSlide).Shapes(k)
oPPTShape.Export "C:\images\s" & k & ".bmp", ppShapeFormatBMP
Next
推荐答案
这并不好,因为它以EMF格式输出每个图像,但是它确实将内联形状集合中的每个图像都写到了一个单独的文件中.当然可以对其进行修改以进行其他形状的收集.
This is not great, as it outputs each image in EMF format, but it does write each of the images in the inline shapes collection to an individual file. It could of course be modified to do the other shapes collection.
我想增强直接写JPG的功能,但是到目前为止,尚不知道VBA在途中通过过滤器推送WRITE输出.因此,要使用这些文件,您需要运行一些外部的后处理/批处理,以将EMF中的文件隐蔽起来以变得更有用.
I would like to enhance to to write JPG directly, but so far do not know the VBA to push WRITE output through a filter on the way. Therefore, to use these files you need to run some outboard post-process/batch to covert the files from EMF to something more usable.
Sub WriteInlineShapesToFile()
Dim docCurrent As Document
Dim shapeCurrent As InlineShape
Dim RC As Integer
Dim vData() As Byte
Dim i As Long
Dim lWritePos As Long
Dim strOutFileName As String
Set docCurrent = ActiveDocument
i = 1
For Each shapeCurrent In docCurrent.InlineShapes
strOutFileName = "c:\temp\datafile" & CStr(i) & ".emf"
Open strOutFileName For Binary Access Write As #1
i = i + 1
vData = shapeCurrent.Range.EnhMetaFileBits
lWritePos = 1
Put #1, lWritePos, vData
Close #1
Next shapeCurrent
RC = MsgBox("Job complete.", vbOKOnly, "Job Status")
End Sub
这篇关于如何使用VBA将Word Shapes保存到图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!