以编程方式从源代码构建 XLA

发布于 2024-09-28 00:34:18 字数 401 浏览 4 评论 0原文

我有一个(版本控制的)VBA 插件导出组件的文件夹(即很多 clsfrmfrx bastxt 文件)。有人可以给我一个构建脚本(可以是 VB 脚本,或更复杂的脚本),该脚本采用此文件夹的名称并生成(工作)XLA 吗?

我知道您可以以编程方式修改 XLA 文件(例如这个问题),所以它不应该编写一个创建空 XLA 的脚本,然后循环遍历文件夹中的所有文件以将它们添加到其中是否太难了...?

谢谢,

尼克

(编辑:Excel 2003,如果有什么不同的话)

I have a (version controlled) folder of exported components of a VBA addin (i.e. a lot of cls, frm, frx, bas and txt files). Can someone give me a build script (can be a VB script, or something more complicated) that takes the name of this folder and produces a (working) XLA?

I know you can programatically modify XLA files (e.g. this question) so it shouldn't be too hard to write a script that creates an empty XLA, and then loops over all the files in the folder to add them to it...?

Thanks,

Nick

(edit: Excel 2003 if it makes any difference)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦巷 2024-10-05 00:34:19

我在 Excel 工作簿中使用一个非常简单的 VBA 宏来执行基本相同的操作,只是我没有任何表单,并且我在格式化文本文件中有一些单元测试信息。由于 VBA 与 VBScript 非常相似,并且下面的代码使用 VBScript 应该可用的文件系统和 Excel 对象模型内容,因此也许它对您有用。

这是 .bas 模块的摘录。我将其放入空白工作簿中,然后将文本文件放入该工作簿所在的任何目录中,然后运行导入。将其重新调整为更正式的用途应该很容易,无论是针对不同的新创建的工作簿的加载项还是在 Excel 之外完成整个构建的脚本:

'...

Private fs_ As FileSystemObject

'...

Private Sub import_()
    On Error GoTo EH

    Set fs_ = New FileSystemObject

    Call importTests_(Application.ThisWorkbook, Application.ThisWorkbook.path)
    Call importCode_(Application.ThisWorkbook, Application.ThisWorkbook.path)

    Exit Sub

EH:
    Debug.Print "Error in import_: " & Err.Number
End Sub

'...
'stuff about importing tests ignored...
'...

Private Sub importCode_(wbk As Workbook, folderName As String)
    Dim folderObj As Folder
    Set folderObj = fs_.GetFolder(folderName)

    Dim fileExt As String

    Dim fileObj As File
    For Each fileObj In folderObj.Files
        fileExt = fs_.GetExtensionName(fileObj.name)

        If fileExt = "bas" Or fileExt = "cls" Then
            Call wbk.VBProject.VBComponents.Import(fileObj.path)
        End If
    Next fileObj
End Sub

'...

我不知道导入有什么问题因为我从来没有在 Excel 中使用过它们。

I use a very simple VBA macro within an Excel workbook to do essentially the same thing, only I don't have any forms, and I have some unit test information in formatted text files. Since VBA is pretty similar to VBScript and the code below uses file system and Excel object model stuff that should be available to VBScript, perhaps it will be useful to you.

This is an excerpt from a .bas module. I drop it in a blank workbook, and then drop my text files in whatever directory that workbook is in, and then run the import. It should be pretty easy to repurpose it for something more formal, whether an add-in that targets a different, newly created, workbook or a script that does the whole build outside of Excel:

'...

Private fs_ As FileSystemObject

'...

Private Sub import_()
    On Error GoTo EH

    Set fs_ = New FileSystemObject

    Call importTests_(Application.ThisWorkbook, Application.ThisWorkbook.path)
    Call importCode_(Application.ThisWorkbook, Application.ThisWorkbook.path)

    Exit Sub

EH:
    Debug.Print "Error in import_: " & Err.Number
End Sub

'...
'stuff about importing tests ignored...
'...

Private Sub importCode_(wbk As Workbook, folderName As String)
    Dim folderObj As Folder
    Set folderObj = fs_.GetFolder(folderName)

    Dim fileExt As String

    Dim fileObj As File
    For Each fileObj In folderObj.Files
        fileExt = fs_.GetExtensionName(fileObj.name)

        If fileExt = "bas" Or fileExt = "cls" Then
            Call wbk.VBProject.VBComponents.Import(fileObj.path)
        End If
    Next fileObj
End Sub

'...

I don't know what the issues are with importing forms since I never use them in Excel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文