當您使用
CreateObject 命令存取 Microsoft Excel 做為 OLE Automation 物件時,增益集、位於 XLStart
目錄中的檔案以及預設的新活頁簿都沒有載入。
當您嘗試載入增益集和檔案時,Excel 傳送訊息給呼叫的應用程式 (例如 Visual
Basic),表示尚未準備好回應要求並且稍候再試。呼叫的程式可能無法處理這個要求,並且會繼續執行其餘的命令。
Microsoft 僅提供示範性的程式設計範例,不做任何明示或默示的保證。其中包括 (但不限於)
其適售性與適合某特定用途之默示擔保。本文假設您已相當熟悉示範所使用的程式設計語言,以及用於建立和偵錯程序的工具。Microsoft
技術支援工程師可以協助說明特定程序的功能,但不會修改這些範例以提供附加功能或建構程序來滿足您的特定需求。
如果要在您將
Excel 執行做為 OLE Automation 物件時載入增益集檔案,請手動載入增益集。這個方法的範例如下所示。
Microsoft Office Excel 2007
Sub LoadAddin()
' Dimension variable xl as object type.
Dim xl As Object
' Activate Microsoft Excel and assign to variable xl.
Set XL = CreateObject("Excel.Application")
' Open the add-in file you want, in this example, XLQUERY.XLAM.
XL.Workbooks.Open (XL.librarypath & "\MSQUERY\XLQUERY.XLAM")
' If you need to register the functions and commands
' contained in a resource (XLL), use the RegisterXLL method.
' In the example below, all functions of Analys32.xll are
' registered.
' XL.RegisterXLL "Analys32.xll"
' Run any auto macros contained in the add-in file
' Auto macros don't run when you open a file
' using the Open method.
XL.Workbooks("xlquery.xlam").RunAutoMacros 1
Set XL = Nothing
End Sub
Microsoft Office Excel 2003 和舊版的 Excel
Sub LoadAddin()
' Dimension variable xl as object type.
Dim xl As Object
' Activate Microsoft Excel and assign to variable xl.
Set XL = CreateObject("Excel.Application")
' Open the add-in file you want, in this example, XLQUERY.XLA.
XL.Workbooks.Open (XL.librarypath & "\MSQUERY\XLQUERY.XLA")
' If you need to register the functions and commands
' contained in a resource (XLL), use the RegisterXLL method.
' In the example below, all functions of Analys32.xll are
' registered.
' XL.RegisterXLL "Analys32.xll"
' Run any auto macros contained in the add-in file
' Auto macros don't run when you open a file
' using the Open method.
XL.Workbooks("xlquery.xla").RunAutoMacros 1
Set XL = Nothing
End Sub
由於 Excel 不會在您呼叫它做為 OLE Automation 物件時載入增益集或 XLStart
目錄中的檔案,因此您對於載入程序具有完全的控制權。如果要載入增益集,您可以手動載入。
這個行為也表示,在藉由
CreateObject 命令呼叫 Excel 時,沒有巨集錯誤、鎖定檔案警示或唯讀檔案警示能夠限制 Excel 載入。這個行為的另一個好處是,載入
Excel 的時間會比在增益集或檔案已載入的情況下進行載入所花費的時間更少。
如需有關如何取得 Visual Basic for Applications
說明的詳細資訊,請按一下下面的文件編號,檢視「Microsoft 知識庫」中的文件:
226118
(http://support.microsoft.com/kb/226118/
)
List of resources that are available to help you learn Visual Basic for Applications programming
文章編號: 213489 - 上次校閱: 2007年6月8日 - 版次: 5.1
這篇文章中的資訊適用於:
- Microsoft Office Excel 2007
- Microsoft Office Excel 2003
- Microsoft Excel 2002 Standard Edition
- Microsoft Excel 2000 Standard Edition
- Microsoft Excel 97 Standard Edition
| kbautomation kbvba kbexpertiseinter kbdtacode kbprb kbprogramming KB213489 |
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。