[英]How can I use external VBA source code with MS Access?
I am writing a VBA script to import data from an Access database to a remote database server. 我正在编写一个VBA脚本,用于将数据从Access数据库导入到远程数据库服务器。 (It happens to be PostgreSQL, but I don't think that's very relevant.) At the moment, my scripts are embedded inside an Access database.
(它恰好是PostgreSQL,但我不认为这是非常相关的。)目前,我的脚本嵌入在Access数据库中。 However, I would like to version my scripts like I do my other source code: as plain text so SVN can give me good change tracking.
但是,我想像我的其他源代码一样对我的脚本进行编辑:作为纯文本,因此SVN可以给我很好的更改跟踪。
I would also prefer not to have to deliver the source files to the client for them to use the script. 我也不希望不必将源文件传递给客户端以供他们使用脚本。 In other words, I would like to deliver the import tool already compiled into the Access database.
换句话说,我想将已编译的导入工具提供给Access数据库。 Is it possible to do so?
有可能这样做吗?
Or am I chasing the wrong rabbit? 还是我在追逐错误的兔子? Is there a way I can use the Access libraries without embedding any code into the Access database?
有没有办法在不将任何代码嵌入Access数据库的情况下使用Access库? My searching suggests not, but I'm open to the possibility.
我的搜索建议不是,但我对这种可能性持开放态度。 This is the first thing I've ever done with VBA, so there's a ton I don't know, I'm sure.
这是我用VBA做过的第一件事,所以有一点我不知道,我敢肯定。
I think I was going down the wrong rabbit hole (and I think I was using a non-existent idiom). 我想我正在走错了兔子洞(而且我认为我使用的是一种不存在的习语)。 Turns out that there are some .NET interop DLLs for Office.
事实证明,Office有一些.NET互操作DLL。 My machine seems to have the .NET interop DLLs already installed with Office, so all I had to do was add a reference to the
Microsoft.Office.Interop.Access
DLL and create an application object: 我的机器似乎已经与Office一起安装了.NET互操作DLL,因此我所要做的就是添加对
Microsoft.Office.Interop.Access
DLL的引用并创建一个应用程序对象:
var app = new Microsoft.Office.Interop.Access.Application();
I think a .NET app is going to be more suited to my needs. 我认为.NET应用程序将更适合我的需求。 I'm not going to be doing a lot of Access specific things.
我不会做很多Access特定的事情。 This will allow me to have my source under version control as usual.
这将允许我照常在版本控制下使用我的源代码。 The only downside is that any development machine (and build server, if I automate the build) will need Access installed, but that was going to happen with a VBA script, anyway.
唯一的缺点是任何开发机器(和构建服务器,如果我自动化构建)将需要安装Access,但无论如何,这将发生在VBA脚本中。
If you don't want to do it within Access, you may want to tag this differently. 如果您不想在Access中执行此操作,则可能需要以不同方式标记。
You can deliver your database to the client as an MDE file, which is a compiled and stand-alone Access database. 您可以将数据库作为MDE文件提供给客户端,MDE文件是一个已编译且独立的Access数据库。 The client will not be able to see the modules or other VBA code in this format, if that is your main concern.
如果这是您主要关注的问题,客户端将无法以此格式查看模块或其他VBA代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.