独立的Excel代码 [英] Standalone code for Excel

查看:112
本文介绍了独立的Excel代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以编写VBA 代码以执行任何 Excel 文件的操作吗?



创建项目时在 Visual Studio 中,它要求将一个 Excel 文件链接到它。我写的所有代码都在 ThisWorkbook.vb 中,因此只对与项目链接的 Excel 文件起作用。





理想情况下,我想要一个脚本:


  1. 当用户双应该允许他/她选择要在该文件上执行的操作的首选Excel文件。

  2. 如果上述不可行我至少要从Excel中文件中调用 VBA 脚本。

基本上,VBA 代码应该独立于任何 Excel 文件。



我看了看

解决方案

答案1



你也可以在VB.Net中做到这一点。只做一个常规项目。 (@SLaks的评论



这对我来说很好,正是我正在寻找的。

答案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:

  1. 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.
  2. 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屋!

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