【问题标题】:Import VBA code from a excel spreadsheet into a access form behind a button将 VBA 代码从 Excel 电子表格导入到按钮后面的访问表单中
【发布时间】:2013-08-31 21:23:24
【问题描述】:

我有一个 Excel 电子表格,其中包含我自己编写的 VBA 脚本。

我经常需要对代码进行一些更改并使用 (ctrl-V) 以按钮后面的形式复制 (ctrl-C) 这段代码(通过点击事件)

当我在电子表格(VBA 代码)中进行更改时,是否可以在 Access 过程中自动执行此操作,以便我可以在 Access 2007 中导入此 VBA 代码?

【问题讨论】:

    标签: excel ms-access vba


    【解决方案1】:

    VBA 中的元编程可能是一个有趣的话题。您需要查找 VBIDE 库。我可能会从CodeModule 对象和Chip Pearson's "Programming The VBA Editor" 开始。

    下面的示例将包含模块名称的模块范围私有常量插入到活动代码窗格中。

    Private Sub insertModuleName()
    ' inserts a module name constant into every module in active project
    
        Dim oPrj As VBProject
        Set oPrj = VBE.ActiveVBProject
        Dim oMod As CodeModule
        Dim oCom As VBComponent
    
        Dim str As String
        str = "Private Const MODULE_NAME As String = "
    
        Dim i As Long
        For i = 1 To oPrj.VBComponents.count
           oPrj.VBComponents.Item(i).CodeModule.InsertLines 3, str & Chr(34) & oPrj.VBComponents.Item(i).NAME & Chr(34)
        Next i
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-15
      • 2015-08-02
      相关资源
      最近更新 更多