Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

一个自动降低VBA宏安全级别的函数

时 间:2008-06-08 22:57:02
作 者:weizw55   ID:2173  城市:青浦
摘 要:可以在系统运行时自动修改安全级别的函数.
正 文:

一个自动降低VBA宏安全级别的函数

 

一般ACCESS的默认的宏安全级别为中级,这时程序在运行时总有许多烦人的提示.而对于普通的ACCESS终端用户来说,他们不会解决这个问题.而我们开发人员为了程序的安全通常是将所有的菜单都禁用掉了.如果让用户自己来改的话呢,则需要写代码来调用系统的菜单.只是这个方法不能自动完成,还是需要终端用自己来选.

以下是一段可以在系统运行时自动修改安全级别的函数.

我先抛砖,请各位大虾一起来发表意见,看看有没有更好的解决之法.

 

Function vbabat1()
'在当前目录下检查是否有VBA.BAT的文件.如果没有,创建一个.并写入数据后运行.以降低VBA的安全级别.
If Dir(CurrentProject.Path & "\VBA.bat") = "" Then

Dim hFile As Long
Dim Str2 As String
Dim str3 As String
 Dim Str4 As String
 Dim str5 As String
 Dim str6 As String
 Dim str7 As String
 Dim str8 As String
 str8 = Chr(34)
 
Str4 = "level"
str7 = "echo off"
str3 = "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Access\Security"
str5 = "reg add " & str8 & str3 & str8 & " /v " & str8 & Str4 & str8 & " /t" & " REG_DWORD /d " & str8 & "00000001" & str8 & " /f"
str6 = "reg delete " & str8 & str3 & str8 & " /v " & str8 & Str4 & str8 & " /f"
Str2 = str7 & Chr(13) & str6 & Chr(13) & str5
hFile = FreeFile
Open (CurrentProject.Path & "\VBA.bat") For Random As hFile
Close hFile
Open (CurrentProject.Path & "\VBA.bat") For Append Access Write As hFile
Print #hFile, str7
Print #hFile, str6
Print #hFile, str5
Close hFile
Call Shell((CurrentProject.Path & "\VBA.bat"), 1)
Else
If DatePart("w", Date) = 2 Then
Call Shell((CurrentProject.Path & "\VBA.bat"), 1)
End If
End If

End Function



Access软件网QQ交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助