Remove protected view from Excel sheet opened programmatically in Access

后端 未结 4 1721
庸人自扰
庸人自扰 2020-12-19 22:02

I have a spreadsheet I open programmatically using the VBA in Access:

Set xl = CreateObject(\"Excel.Application\")
With xl
    Call RunASCFormatting(xl, wb,          


        
4条回答
  •  执笔经年
    2020-12-19 22:34

    One possibility is to change the macro security settings programmatically to the lowest before you open the Excel workbook. After manipulating your data, re-enable the previous setting of the macro security.

    Here's some revised code which I found at http://www.mrexcel.com/forum/excel-questions/631545-change-trust-center-settings-visual-basic-applications.html:

    Public Sub MySubroutine()
        Dim lSecurity As Long
    
        lSecurity = Application.AutomationSecurity
        Application.AutomationSecurity = msoAutomationSecurityLow
    
        '''''''''''''''''''''
        '   Run code here   '
        '''''''''''''''''''''
    
        Application.AutomationSecurity = lSecurity
    End Sub
    

    As a side comment, VBA implements Integer as Long, so it could actually be slightly more performance degrading to declare Integer variables as it has to reinterpret the Integer keyword. When I learned that, I started declaring an Integer as Long instead. I actually read this in some Microsoft documentation, but I lost the link to it years ago.

提交回复
热议问题