从MS Excel VBA,在MS Access中创建一个标准模块 [英] From MS Excel VBA, create a Standard Module in MS Access

查看:226
本文介绍了从MS Excel VBA,在MS Access中创建一个标准模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Excel(2013)中的VBA,我需要在MS Access(2013)数据库中创建一个标准模块.我愿意接受所有想法-谢谢!

From VBA in Excel (2013), I need to create a standard module in a MS Access (2013) database. I am open to any and all ideas - Thanks!

推荐答案

先前解决方案的自然发展是希望向新模块中添加代码.我决定采取替代方法,然后将现有的标准模块导入"到远程MS Access数据库中.演进的最后一步是远程运行导入到远程数据库的标准模块中的过程.同样,此代码位于Excel VBA中.完成这两个任务的代码如下:

The natural evolution of the previous solution is to want to add code to the new module. I decided to take an alternate route and "import" an existing standard module into the remote MS Access db. A final step in the evolution is to remotely run a procedure that is within the standard module that was imported into the remote db. Again, this code is located in Excel VBA. The code that accomplishes these two tasks are as follows:

'FROM EXCEL, REMOTELY INSTRUCT A MS ACCESS db   
'IMPORTS .BAS FILE INTO db
'EXECUTE THE 'RoutineWithinModule1' THAT IS WITHIN MODULE1 OF THE REMOTE db

Dim appAccess As Access.Application
Set appAccess = New Access.Application

With appAccess
    .OpenCurrentDatabase "C:\Temp\MyDB_DEV_1.mdb"
    .VBE.ActiveVBProject.VBComponents.Import "C:\Module1.bas"
    .DoCmd.Save acModule, "Module1"
    .Run "RoutineWithinModule1"
    .CloseCurrentDatabase
    .Quit
End With

Set appAccess = Nothing

这篇关于从MS Excel VBA,在MS Access中创建一个标准模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆