2010-06-03 96 views
1

我很好奇如何最好地處理這種情況。我有一箇舊的VBA工作簿,工作得很好。不幸的是,使用Office 2007/2010中的新安全措施,您會收到「安全警告某些活動內容已被禁用」消息。我知道我可以點擊郵件並選擇啓用內容或將其添加到受信任的位置。不幸的是,每一次這樣做對終端用戶來說都是一種痛苦。所以我在Visual Studio中創建了一個安裝項目,它將啓動一個控制檯應用程序,將該文件複製到模板文件夾,然後在桌面上放置一個快捷方式。保持它是一個麻煩,雖然因爲我不添加更新到Excel文件,工程師。所以我必須重新創建一個32位/ 64位的setup.exe。辦公室值得信賴的地點

什麼是最佳解決方案?

它需要與Windows Vista/7 32/64位和Office 2007/2010 32位一起使用,並且用戶在計算機技能方面會有所不同。

+0

是您的自我認證選項: http://office.microsoft.com/en-us/access/HP010397921033.aspx? – Fionnuala 2010-06-03 07:19:35

+0

這麼貴嗎? – 2010-06-04 12:46:06

回答

0

我有類似的情況,照顧了它的一些註冊表項。

HKCU\Software\Microsoft\Office\12.0\Excel\Security\Trusted Locations\AllowNetworkLocations=1 [DWORD] 
HKCU\Software\Microsoft\Office\12.0\Excel\Security\AccessVBOM=1 [DWORD] 
KHCU\Software\Microsoft\Office\12.0\Excel\Security\VBAWarnings=1 [DWORD] 
KHLM\Software\Microsoft\Office\Common\Security\UFIControls=1 [DWORD] 

也許快速谷歌搜索VBA安全註冊表項可以幫助你。

0

這裏遲到了,但這是一個常見的煩惱:您需要定義一個'可信位置'。

大部分開發商遇到時,他們的代碼試圖打開一個電子表格文件,你所看到的問題,他們得到這種無益的錯誤信息:

「辦公室已檢測到該文件中的問題爲幫助保護您的計算機。此文件無法打開。「

如果你是中級到專家的VBA編碼器(或與任何常見的腳本語言)查找由丹尼爾Pineault上DevHut.net在2010年公佈的受信任位置代碼:

DevHut code example: Trusted Location using VBScript

爲了您的方便,這是我在Excel中實現它:

 

Public Sub TrustThisFolder(Optional FolderPath As String, _                            Optional TrustSubfolders As Boolean = True, _                            Optional TrustNetworkFolders As Boolean = False, _                            Optional sDescription As String)

' Add a folder to the 'Trusted Locations' list so that your project's VBA can ' open Excel files without raising errors like "Office has detected a problem ' with this file. To help protect your computer this file cannot be opened."

' Ths function has been implemented to fail silently on error: if you suspect ' that users don't have permission to assign 'Trusted Location' status in all ' locations, reformulate this as a function returning True or False

' Nigel Heffernan January 2015 ' ' Based on code published by Daniel Pineault in DevHut.net on June 23, 2010: ' www.devhut.net\2010\06\23\vbscript-createset-trusted-location-using-vbscript\

' **** **** **** ****  THIS CODE IS IN THE PUBLIC DOMAIN  **** **** **** ****

' UNIT TESTING: ' ' 1:    Reinstate the commented-out line 'Debug.Print sSubKey & vbTab & sPath ' 2:    Open the Immediate Window and run this command: '           TrustThisFolder "Z:\", True, True, "The user's home directory" ' 3:    If  "Z:\"  is already in the list, choose another folder ' 4:    Repeat step 2 or 3: the folder should be listed in the debug output ' 5:    If it isn't listed, disable the error-handler and record any errors '

On Error GoTo ErrSub

Dim sKeyPath    As String

Dim oRegistry   As Object Dim sSubKey     As String Dim oSubKeys    ' type not specified. After it's populated, it can be iterated Dim oSubKey     ' type not specified.

Dim bSubFolders         As Boolean Dim bNetworkLocation    As Boolean

Dim iTrustNetwork       As Long

Dim sPath   As String Dim sDate   As String Dim sDesc   As String Dim i       As Long

Const HKEY_CURRENT_USER = &H80000001

bSubFolders = True bNetworkLocation = False

If FolderPath = "" Then     FolderPath = FSO.GetSpecialFolder(2).Path     If sDescription = "" Then         sDescription = "The user's local temp folder"     End If End If

If Right(FolderPath, 1) <> "\" Then     FolderPath = FolderPath & "\" End If

 

sKeyPath = "" sKeyPath = sKeyPath & "SOFTWARE\Microsoft\Office\" sKeyPath = sKeyPath & Application.Version sKeyPath = sKeyPath & "\Excel\Security\Trusted Locations\"       Set oRegistry = GetObject("winmgmts:\.\root\default:StdRegProv") '   Note: not the usual \root\cimv2  for WMI scripting: the StdRegProv isn't in that folder   oRegistry.EnumKey HKEY_CURRENT_USER, sKeyPath, oSubKeys

For Each oSubKey In oSubKeys

    sSubKey = CStr(oSubKey)     oRegistry.GetStringValue HKEY_CURRENT_USER, sKeyPath & "\" & sSubKey, "Path", sPath          'Debug.Print sSubKey & vbTab & sPath              If sPath = FolderPath Then         Exit For     End If     

     Next oSubKey

If sPath <> FolderPath Then

    If IsNumeric(Replace(sSubKey, "Location", "")) Then         i = CLng(Replace(sSubKey, "Location", "")) + 1     Else         i = UBound(oSubKeys) + 1     End If          sSubKey = "Location" & CStr(i)          If TrustNetworkFolders Then         iTrustNetwork = 1         oRegistry.GetDWORDValue HKEY_CURRENT_USER, sKeyPath, "AllowNetworkLocations", iTrustNetwork         If iTrustNetwork = 0 Then             oRegistry.SetDWORDValue HKEY_CURRENT_USER, sKeyPath, "AllowNetworkLocations", 1         End If     End If          oRegistry.CreateKey HKEY_CURRENT_USER, sKeyPath & "\" & sSubKey     oRegistry.SetStringValue HKEY_CURRENT_USER, sKeyPath & "\" & sSubKey, "Path", FolderPath     oRegistry.SetStringValue HKEY_CURRENT_USER, sKeyPath & "\" & sSubKey, "Description", sDescription     oRegistry.SetDWORDValue HKEY_CURRENT_USER, sKeyPath & "\" & sSubKey, "AllowSubFolders", 1      End If

ExitSub:

    Set oRegistry = Nothing     Exit Sub

ErrSub:          Resume ExitSub

End Sub

做什麼,請保持代碼的確認,如果你重用它:這會區分你(和來自其他帖子和其他專家(和其他人)在沒有確認的情況下交換知識的網站。