Remove protected view from Excel sheet opened programmatically in Access

后端 未结 4 1696
庸人自扰
庸人自扰 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:19

    Sub trusted_locations(path_to_add)
    
        Const HKEY_CURRENT_USER = &H80000001
    
        Dim oRegistry
        Dim sDescription        'Description of the Trusted Location
        Dim bAllowSubFolders        'Enable subFolders as Trusted Locations
        Dim bAllowNetworkLocations  'Enable Network Locations as Trusted
                        '   Locations
        Dim bAlreadyExists
        Dim sParentKey
        Dim iLocCounter
        Dim arrChildKeys
        Dim sChildKey
        Dim sValue
        Dim sNewKey
        Dim vers As Variant
    
    'Determine the location/path of the user's MyDocuments folder
    '*******************************************************************************
        Set oRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
        bAllowSubFolders = True
        bAlreadyExists = False
    
        vers = Application.Version
    
        sParentKey = "Software\Microsoft\Office\" & vers & "\Excel\Security\Trusted Locations"
    
        iLocCounter = 0
        oRegistry.EnumKey HKEY_CURRENT_USER, sParentKey, arrChildKeys
        For Each sChildKey In arrChildKeys
            oRegistry.GetStringValue HKEY_CURRENT_USER, sParentKey & "\" & sChildKey, "Path", sValue
            If sValue = spath Then bAlreadyExists = True
    
            If CInt(Mid(sChildKey, 9)) > iLocCounter Then
                    iLocCounter = CInt(Mid(sChildKey, 9))
                End If
        Next
    
    'Uncomment the following 4 linesif your wish to enable network locations as Trusted
    '   Locations
       bAllowNetworkLocations = True
       If bAllowNetworkLocations Then
               oRegistry.SetDWORDValue HKEY_CURRENT_USER, sParentKey, "AllowNetworkLocations", 1
       End If
    
        If bAlreadyExists = False Then
            sNewKey = sParentKey & "\Location" & CStr(iLocCounter + 1)
    
            oRegistry.CreateKey HKEY_CURRENT_USER, sNewKey
            oRegistry.SetStringValue HKEY_CURRENT_USER, sNewKey, "Path", path_to_be_added
            oRegistry.SetStringValue HKEY_CURRENT_USER, sNewKey, "Description", description_of_path
    
            If bAllowSubFolders Then
                oRegistry.SetDWORDValue HKEY_CURRENT_USER, sNewKey, "AllowSubFolders", 1
            End If
        End If
    End Sub
    

提交回复
热议问题