如何将MDB文件批量转换为ACCDB格式及批量加上密码

image_print阅读模式

在access中找开一个空数据库,建立下面的模板并运行。

Option Compare Database

Sub ConvertAndEncrypt()
    '定义变量
    Dim strPath As String '目录路径
    Dim strFile As String '文件名
    Dim strNewFile As String '新文件名
    Dim strPassword As String '密码
    Dim accApp As Access.Application 'Access 应用程序对象
    
    '设置目录路径和密码
    strPath = "E:\Downloads\modify\" '你的目录路径,最后要加上\
    newstrPath = "E:\Downloads\定额库AccDb版本\" '你的目录路径,最后要加上\
    strPassword = "BZZhouDingBo" '你的密码
    
    '创建 Access 应用程序对象
    Set accApp = New Access.Application
    
    '循环遍历目录中的 MDB 文件
    strFile = Dir(strPath & "*.mdb")
    Do While strFile <> ""
        '生成新文件名,将扩展名改为 accdb
        strNewFile = Left(strFile, Len(strFile) - 3) & "accdb"       
        accApp.ConvertAccessProject SourceFilename:=strPath & strFile, DestinationFilename:=newstrPath & strNewFile, DestinationFileFormat:=acFileFormatAccess2007       
        '删除原始 MDB 文件(如果不需要,可以注释掉)
        'Kill strPath & strFile
        '获取下一个 MDB 文件名
        strFile = Dir()
    Loop
    
    '退出 Access 应用程序对象
    accApp.Quit
    
End Sub

为accdb数据库批量加上密码

Sub SetPasswordForDatabases()

    Dim strPath As String '目录路径
    Dim strFile As String '文件名
    Dim strPassword As String '密码
    Dim accApp As Access.Application 'Access 应用程序对象

    '设置目录路径和密码
    strPath = "E:\Downloads\定额库AccDb版本\" '替换为您的目录路径,确保路径最后有一个反斜杠(\)
    strPassword = "xycost.com" '替换为您的密码

    '创建 Access 应用程序对象
    Set accApp = New Access.Application

    '循环遍历目录中的 ACCDB 文件
    strFile = Dir(strPath & "*.accdb")
    Do While strFile <> ""
        '打开 ACCDB 文件
        accApp.OpenCurrentDatabase strPath & strFile, True
        '设置密码
        accApp.CurrentProject.Connection.Execute "ALTER DATABASE PASSWORD [" & strPassword & "] []"
        '关闭当前数据库
        accApp.CloseCurrentDatabase
        '获取下一个 ACCDB 文件名
        strFile = Dir()
    Loop

    '退出 Access 应用程序对象
    accApp.Quit
    Set accApp = Nothing

End Sub
0

评论0

请先
DB33/1092-2021 浙江省绿色建筑设计标准
DB33/1092-2021 浙江省绿色建筑设计标准
9分钟前 有人购买 去瞅瞅看
没有账号?注册  忘记密码?

社交账号快速登录

微信扫一扫关注
扫码关注后会自动登录网站