2010-06-03 72 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

做什么,请保持代码的确认,如果你重用它:这会区分你(和来自其他帖子和其他专家(和其他人)在没有确认的情况下交换知识的网站。