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.