从 C# 调用 VBA 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1798099/
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
Call VBA function from C#
提问by Max
Is it possible to call a VBA function (in Access) which takes two string parameters from the outside world (for instance from c# but others will do too)?
是否可以调用一个 VBA 函数(在 Access 中),它从外部世界(例如来自 c# 但其他人也会这样做)接受两个字符串参数?
采纳答案by Irwin M. Fletcher
This is an example of a call from C# to an access database function that I have used in the past to create a similar feature.
这是从 C# 调用访问数据库函数的示例,我过去曾使用该函数创建类似的功能。
private void btnRunVBAFunction_Click(object sender, System.EventArgs e)
{
Access.Application acApp = new Access.ApplicationClass();//create msaccess
application
acApp.OpenCurrentDatabase(@"C:\temp\db1.mdb",false ,null);//open mdb file
object oMissing = System.Reflection.Missing.Value;
//Run the Test macro in the module
acApp.Run("Test",ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing
,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing
,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing
,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing
,ref oMissing,ref oMissing);
acApp.Quit();//exit application
}
This is the site that I have used in the past.
这是我过去使用过的网站。
http://bytes.com/topic/c-sharp/answers/255310-run-microsoft-access-module-vs-net-c
http://bytes.com/topic/c-sharp/answers/255310-run-microsoft-access-module-vs-net-c
回答by stuartd
There's a KB article on automating Access from C#which should get you started.
有一篇关于从 C# 自动化访问的知识库文章应该可以帮助您入门。