2009-11-25 113 views
3

是否可以调用一个VBA函数(在Access中),它从外部世界接受两个字符串参数(例如来自c#,但其他人也会这样做)?从C#调用VBA函数

回答

1

这是一个从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 
} 

这是我过去使用的网站。

http://bytes.com/topic/c-sharp/answers/255310-run-microsoft-access-module-vs-net-c