2016-05-23 93 views
2

我在MS Excel 2010中創建了一個VBA應用程序。它有一個用戶窗體。在那裏,我想添加一個功能來打開(MS Word)文件的支持和常見問題的目的。我不想將文件保存在中央位置,然後通過VBA打開文件。是否有可能將文件存儲在vba項目中?將文件存儲在VBA項目中並打開它

+0

我不認爲那可能出盒子。 – litelite

+0

我在想,也許我可以將文件存儲在Excel壓縮文件中...任何解決方案都將非常感謝。 – blckbird

+0

_excel zip file_ – litelite

回答

3

您可以在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 
2

您可以存儲內容,在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>" 
相關問題