我很好奇如何最好地处理这种情况。我有一个旧的VBA工作簿,可以正常工作。遗憾的是,使用Office 2007/2010中的新安全措施,您会收到“安全警告某些活动内容已被禁用”消息。我知道我可以单击该消息并选择启用内容或将其添加到受信任位置。不幸的是,每次这样做对最终用户来说都是一种痛苦。因此,我在Visual Studio中创建了一个安装项目,该项目将启动一个控制台应用程序,该应用程序将文件复制到模板文件夹,然后在桌面上放置一个快捷方式。维护它是一件麻烦事,因为我没有为Excel文件添加更新,工程师会这样做。所以我必须重新创建一个32/64位的setup.exe。
什么是最佳解决方案?
它需要与Windows Vista / 7 32/64位和Office 2007/2010 32位一起使用,并且用户的计算机技能会有所不同。
答案 0 :(得分:0)
将此链接发送给所有用户。如何确保在启用宏的情况下打开文件是一个非常好的演练。它还根据您的具体情况为您提供了一些不同的方法。
答案 1 :(得分: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安全注册表项可以帮助您。
答案 2 :(得分:0)
这里游戏的后期,但这是一个常见的烦恼:你需要定义一个'可信位置'。
大多数开发人员遇到了他们的代码尝试打开电子表格文件时遇到的问题,他们收到了这条无用的错误消息:
“Office检测到此文件存在问题。为了保护您的计算机,无法打开此文件。”
如果您是VBA编码器(或使用任何常用脚本语言)的中级专家,请查看2010年Daniel Pineault在DevHut.net上发布的可信位置代码:
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
如果您重复使用,请保留代码中的确认:这将区分您(和StackOverflow)与其他帖子和其他专家(和其他人)未经确认交换知识的网站。