将文件存储在VBA项目中并打开它
问题描述:
我在MS Excel 2010中创建了一个VBA应用程序。它有一个用户窗体。在那里,我想添加一个功能来打开(MS Word)文件的支持和常见问题的目的。我不想将文件保存在*位置,然后通过VBA打开文件。是否有可能将文件存储在vba项目中?将文件存储在VBA项目中并打开它
答
您可以在Excel Worskeet(插入 - >对象)中嵌入对象。如果您单击嵌入的对象,在左上角您将看到对象的名称(例如“对象7”)。这样,您可以通过在VBA中打开它
Sub openEmbed()
Dim ole As OLEObject, wdoc As Word.Document
Set ole = Worksheets("Sheet1").OLEObjects("Object 7")
ole.Activate
Set wdoc = ole.Object
End Sub
答
您可以存储内容,在VBA XML,然后用InsertXML
在新文档中插入:
Dim app As Object
Set app = CreateObject("Word.Application")
app.Visible = True
app.Documents.Add.Content.InsertXML "<?xml version=""1.0""?><abc:books xmlns:abc=""urn:books"" " & _
"xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" " & _
"xsi:schemaLocation=""urn:books books.xsd""><book>" & _
"<author>Matt Hink</author><title>Migration Paths of the Red " & _
"Breasted Robin</title><genre>non-fiction</genre>" & _
"<price>29.95</price><pub_date>2006-05-01</pub_date>" & _
"<abstract>You see them in the spring outside your windows. " & _
"You hear their lovely songs wafting in the warm spring air. " & _
"Now follow their path as they migrate to warmer climes in the fall, " & _
"and then back to your back yard in the spring.</abstract></book></abc:books>"
我不认为那可能出盒子。 – litelite
我在想,也许我可以将文件存储在Excel压缩文件中...任何解决方案都将非常感谢。 – blckbird
_excel zip file_ – litelite