使用VBA将文件嵌入到Word文档中 [英] Embed a file into a Word doc using VBA

查看:791
本文介绍了使用VBA将文件嵌入到Word文档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Word 2010在Access 2010中执行此操作.我有一个WordDoc对象,无法找到嵌入文件的方法.

I am attempting to do this from Access 2010 using Word 2010. I have a WordDoc object and cannot find a way to embed a file.

我尝试使用书签从零开始:

I tried starting from nothing using a bookmark:

bmFile.Range.InsertFile "C:\Users\Me\Desktop\TestFile.xlsx"

并引发了有关文件已损坏的错误.

and that trew an error about the File being corrupted.

我尝试使用WordDoc.InlineShapes(1)编辑现有的嵌入文件,但是没有属性可更改或不相关.

I tried editing an existing embeded file using WordDoc.InlineShapes(1) but no properties were changable or relevant.

任何想法都将不胜感激.

Any ideas would be greatly appreciated.

谢谢

推荐答案

从现有文件(按照您的示例),您应该可以做到这一点

From an existing file (as per your example) you should be able to do this

bmFile.Range.InlineShapes.AddOLEObject ClassType:="Excel.Sheet.12", _
  FileName:="C:\Users\Me\Desktop\TestFile.xlsx", _
  LinkToFile:=False, _
  DisplayAsIcon:=False

在不使用文件的情况下插入对象实际上是比较麻烦的.您可以通过将FileName参数设置为"来完成此操作,但是OLE服务器将启动并显示其UI(从文件中嵌入时不会发生).

It's actually nastier to insert an object without using a file. You can do it by setting the FileName parameter to "", but then the OLE server will be started and display its UI (which doesn't happen when you embed from a file).

对于修改嵌入式对象中的任何内容,它并不是特别简单,因为对象的UI会妨碍您的操作,但是起点是Shape(或InlineShape)的OLEFormat成员.很难找到,因为"OLEFormat"不是一个特别有用的名称.

As for modifying anything in the embedded object, it isn't particularly straightforward because the object's UI tends to get in the way, but the starting point is the OLEFormat member of the Shape (or InlineShape). Difficult to find because "OLEFormat" is not a particularly informative name.

这篇关于使用VBA将文件嵌入到Word文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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