如何使用 VBA 将字形保存为图像? [英] How to save Word Shapes to image using VBA?

查看:32
本文介绍了如何使用 VBA 将字形保存为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的要求,将嵌入 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:imagess" & 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:	empdatafile" & 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 将字形保存为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆