获取 VBA/Access 源代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6755639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:40:32  来源:igfitidea点击:

Getting at VBA/Access Source Code

ms-accessvbadecompiler

提问by bumble_bee_tuna

I'm rewriting a legacy access / VBA application in C#. While I am limited as a VBA programmer I am under the impression that the code is minimally compiled and runs almost as a script ? Obviously no security / VBA you can just hit alt+ f11to get at the source code is there a good way to decompile / get at this code?

我正在用 C# 重写一个旧的访问/VBA 应用程序。虽然我作为 VBA 程序员受到限制,但我的印象是代码经过最少编译并且几乎作为脚本运行?显然没有安全性/ VBA 你可以点击alt+f11来获取源代码 有没有一种反编译/获取这段代码的好方法?

So I tried this: http://forums.databasejournal.com/showthread.php?t=34222

所以我试过这个:http: //forums.databasejournal.com/showthread.php?t=34222

which appears to be about how to decompile .mdbfiles.

这似乎是关于如何反编译.mdb文件。

However the program quickly recompiled itself - or at least says it is recompiling itself in the lower left status bar. Any ideas?

然而,程序很快就重新编译了自己——或者至少在左下方的状态栏中说它正在重新编译自己。有任何想法吗?

回答by David-W-Fenton

Here are some suggestions (some of which I'm repeating from comments I've made above):

以下是一些建议(其中一些我从我上面所做的评论中重复了一遍):

  • Alt-F11 is not my usual method of opening the VBE, because I usually want to go to the Immediate Windows. Try Ctrl-G, instead.

  • If both Alt-F11 and Ctrl-G fail to open the VBE, then perhaps the AllowBypassKey property of the database has been changed to False. To get code to change this, search the Access help file for AllowBypassKey (in the VBE, from the help menu, search for "AllowBypassKey"). However, you won't be able to run the code within the database you're trying to investigate if AllowBypassKey is turned OFF, so you can run this code:

  • Alt-F11 不是我通常打开 VBE 的方法,因为我通常想转到即时窗口。改为尝试 Ctrl-G。

  • 如果 Alt-F11 和 Ctrl-G 都无法打开 VBE,则可能是数据库的 AllowBypassKey 属性已更改为 False。要获取更改此设置的代码,请在 Access 帮助文件中搜索 AllowBypassKey(在 VBE 中,从帮助菜单中搜索“AllowBypassKey”)。但是,如果 AllowBypassKey 关闭,您将无法在您尝试调查的数据库中运行代码,因此您可以运行以下代码:

//

//

  On Error GoTo Change_Err
    Dim db As DAO.Database
    Dim prp As Variant
    Const conPropNotFoundError = 3270

    Set db = DBEngine.OpenDatabase("C:\Databases\MyDatabase.mdb")
    db.Properties("AllowBypassProperty") = True

  exitRoutine:
    If Not (db Is Nothing) Then
       db.Close
       Set db = Nothing
    End If
    Exit Sub

  errHandler:
    If Err = conPropNotFoundError Then    ' Property not found.
       ' do nothing and exit
       Resume exitRoutine
    End If

Then you should be able to open the database when holding down the SHIFT key (which bypasses any defined startup routines, which might have been shutting off access to the VBE).

然后,您应该能够在按住 SHIFT 键时打开数据库(这会绕过任何定义的启动例程,这些例程可能会关闭对 VBE 的访问)。

  • If the file is an MDE, there is no source code. You can find out if it's an MDE by checking this property:

    ?CurrentDB.Properties("MDE")

  • 如果文件是 MDE,则没有源代码。您可以通过检查此属性来确定它是否是 MDE:

    ?CurrentDB.Properties("MDE")

If it's an MDE (the file can have any extension), this will return "T". If it's not an MDE, it will throw an error (because the property doesn't exist).

如果它是 MDE(文件可以有任何扩展名),这将返回“T”。如果它不是 MDE,则会抛出错误(因为该属性不存在)。

  • Other things to check might be how many modules there are. If you have the database open and can get to the Immediate Windows (Ctrl-G), then this will tell you if there are any modules:
  • 其他需要检查的事情可能是有多少模块。如果您打开了数据库并且可以进入即时窗口 (Ctrl-G),那么这将告诉您是否有任何模块:

//

//

  ?CurrentProject.AllModules.Count
  • You also might be able to see what's in the database by opening up the Object Browser in the VBE (F2) and selecting the project name in the dropdown at the top (it will say "" by default

  • Last of all, you may think that it could be protected by Jet ULS, but starting with Access 2000, that's not a big possible, as there's nothing but a password on the VBA project available (i.e., it's no longer covered under Jet ULS). I would expect that if it were password-protected, you'd be prompted for the password somewhere along the line, so you'd already know that.

  • 您还可以通过在 VBE (F2) 中打开对象浏览器并在顶部的下拉列表中选择项目名称(默认情况下会显示“”)来查看数据库中的内容

  • 最后,您可能认为它可以受到 Jet ULS 的保护,但从 Access 2000 开始,这不太可能,因为 VBA 项目上只有密码可用(即,Jet ULS 不再涵盖它) . 我希望如果它受密码保护,系统会提示您输入密码,所以您已经知道了。

回答by Mitch Wheat

If it's an .mdeyou are out of luck. You need to get hold of the .mdbcontaining the source VBA code that was compiled to create the .mde

如果它是.mde你运气不好。您需要掌握.mdb包含已编译的源 VBA 代码以创建.mde

回答by bumble_bee_tuna

  1. Navigate to the Program Folders on your computer.

  2. Open the MS Office Folder

  3. Navigate to MSAccess.exe and make a shortcut of it.

  4. Move the shortcut to where your database resides (makes life easier and you'll need to do this for each database to decompile).

  5. (optional) Rename the shortcut to something like "decompiler for my database whose name is...." so you know that opening it blows away your compiled code

  6. Right-click on the shortcut to view its properties. In the Target field of the properties dialog box for the shortcut you'll see something like "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE"

  7. In the target field, right-arrow to the end of the pathname, type a space, and then, in quotes, type (or paste) the full pathname of the location of your MS Access file to decompile (easiest way is to copy from the address bar on your window where the file resides, if you have the address bar showing).

  8. Still in the Target field, type a space, and then with no quotes, type /decompile

  9. Click OK to accept the changes and to close the dialog box.

  10. Hold the Shift key down and keep it down.

  11. Wiggle your ears

  12. Double-click on the shortcut.

  13. Go to any module in your database.

  1. 导航到计算机上的程序文件夹。

  2. 打开 MS Office 文件夹

  3. 导航到 MSAccess.exe 并创建它的快捷方式。

  4. 将快捷方式移动到您的数据库所在的位置(使生活更轻松,您需要为每个数据库执行此操作以进行反编译)。

  5. (可选)将快捷方式重命名为“我的数据库的反编译器,其名称是....”这样你就知道打开它会吹走你的编译代码

  6. 右键单击快捷方式以查看其属性。在快捷方式属性对话框的目标字段中,您将看到类似“C:\Program Files\Microsoft Office\Office\MSACCESS.EXE”的内容

  7. 在目标字段中,向右箭头指向路径名的末尾,键入一个空格,然后在引号中键入(或粘贴)要反编译的 MS Access 文件位置的完整路径名(最简单的方法是从文件所在窗口上的地址栏(如果显示地址栏)。

  8. 仍然在目标字段中,键入一个空格,然后不带引号,键入 /decompile

  9. 单击“确定”接受更改并关闭对话框。

  10. 按住 Shift 键并保持按下。

  11. 动动耳朵

  12. 双击快捷方式。

  13. 转到数据库中的任何模块。

回答by maneesh

  • HOW TO VIEW SOURCE CODE (.mdb FILE)
    1. Select the file
    2. Hold the 'shift' key
    3. Then double click the file without releasing the 'shift' key
  • 如何查看源代码(.mdb 文件)
    1. 选择文件
    2. 按住“shift”键
    3. 然后双击文件而不释放'shift'键