独立的Excel代码 [英] Standalone code for Excel
问题描述
可以编写VBA 代码以执行任何 Excel 文件的操作吗?
创建项目时在 Visual Studio 中,它要求将一个 Excel 文件链接到它。我写的所有代码都在 ThisWorkbook.vb
中,因此只对与项目链接的 Excel 文件起作用。
理想情况下,我想要一个脚本:
- 当用户双应该允许他/她选择要在该文件上执行的操作的首选Excel文件。
- 如果上述不可行我至少要从Excel中文件中调用 VBA 脚本。
基本上,VBA 代码应该独立于任何 Excel 文件。
我看了看
答案1
你也可以在VB.Net中做到这一点。只做一个常规项目。 (@SLaks的评论)
这对我来说很好,正是我正在寻找的。 p>
答案2
@ErikEidt发布的非常具描述性的 answer
我没有尝试过,但它似乎是一个很好的替代方法来获取宏。
Can VBA code be written to perform actions on any Excel file?
When I create a project in Visual Studio, it asks for an Excel file to be linked to it. All the code that I write is in ThisWorkbook.vb
and hence acts only on the Excel file linked to the project.
Ideally, I want a script that:
- When the user double-clicks, he/she should be allowed to select an Excel file of choice for the actions to be performed on that file.
- If the above is not possible, I'd at least like to invoke the VBA script from within an Excel file.
Basically, the VBA code should be independent of any Excel file.
I looked at VBScript, but the syntax for it seems to differ slightly.
Answer 1
You can do that in VB.Net too. Just make a regular project. (comment by @SLaks)
This worked for me very well and was exactly what I was looking for.
Answer 2
The very descriptive answer posted by @ErikEidt
I haven't tried this, but it seems like a good and alternative way of getting macros to work.
这篇关于独立的Excel代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!