(Excel) 的 Application.AutomationSecurity 屬性

會傳回或設定 MsoAutomationSecurity 常數,代表 Microsoft Excel 以程式設計方式開啟檔案時所使用的安全性模式。 讀取/寫入。

語法

運算式AutomationSecurity

expression 代表 Application 物件的變數。

註解

此屬性會自動時設定為 msoautomationsecuritylow-會 啟動應用程式。 因此,若要避免中斷的預設設定依賴解決方案,您應該小心至 msoautomationsecuritylow-會 重設此屬性之後以程式設計方式開啟檔案。 此外,為避免遭受惡意攻擊,以程式自動開啟檔案前後,應該要立即設定此屬性。

MsoAutomationSecurity 可以為下列其中一個 MsoAutomationSecurity 常數:

  • msoAutomationSecurityByUI。 Uses the security setting specified in the Security dialog box.

  • msoAutomationSecurityForceDisable。 會停用以程式開啟之所有檔案中的所有巨集,而不會顯示任何安全性提醒。

    注意事項

    這項設定不會停用 Microsoft Excel 4.0 巨集。 如果以程式設計方式開啟包含 Microsoft Excel 4.0 宏的檔案,系統會提示使用者決定是否要開啟檔案。

  • msoAutomationSecurityLow。 會啟用所有巨集。 這是應用程式啟動時的預設值。

ScreenUpdating 設定False 並不會影響警示,也不會影響安全性警告。

DisplayAlerts設定不會套用至安全性警告。 例如,如果使用者在使用者處於中等安全性層級時,將 DisplayAlerts 設定為 False ,並將 AutomationSecurity 設定為 msoAutomationSecurityByUI ,則宏執行時會出現安全性警告。 這可讓巨集截獲檔案開啟錯誤,但在順利開啟檔案時,仍會顯示安全性警告。

範例

本範例會擷取目前的自動化安全性設定、變更設定停用巨集、顯示 [開啟舊檔] 對話方塊,並在開啟選取的檔案後將自動化安全性變更回原來的設定。

Sub Security() 
    Dim secAutomation As MsoAutomationSecurity 
 
    secAutomation = Application.AutomationSecurity 
 
    Application.AutomationSecurity = msoAutomationSecurityForceDisable 
    Application.FileDialog(msoFileDialogOpen).Show 
 
    Application.AutomationSecurity = secAutomation 
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應