0

I am trying to use an external vbs file in my excel macro. The vbs file contains classes and methods which I want to use.

But ExecuteGlobal not working. I have tried to search a lot but all the posts are nearly five years old leaving few. There is no error in vbs file and tried it with another text file but it is showing compile time error at same place only Can any one help me.

enter image description here

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
smith
  • 87
  • 7
  • 2
    `ExecuteGlobal` does not exist in VBA. – Pᴇʜ May 15 '20 at 07:52
  • VBS can mostly be pasted into VBA. –  May 15 '20 at 07:54
  • @Mark good luck. I would say in most cases you would need at least to adjust the code. What you say may be true for some statements but not for an entire code. – Pᴇʜ May 15 '20 at 07:58
  • Anything not wrapped in a class is able to be pasted into VBA. That was a design goal of VBScript. When VBA was released MS promoted a coding style the exact same as VBScript. People whinged about performance and MS changed their tune. –  May 15 '20 at 08:33
  • 1
    @Mark I mean if you have a VBScript that interacts with an Excel wonkbook/sheet already you would need to re-write that part, as it could not interact with `ThisWorkbook` in your Excel file then. Also it would be recommended to use typed variables in VBA (which VBS does not support). So even if a code change is only necessary in the first case a review is highly recommended. • Furthermore the OP said the VBS uses classes so that would not be able to run with just pasting. – Pᴇʜ May 15 '20 at 08:42
  • Does this answer your question? [VBA execute code in string](https://stackoverflow.com/q/42231887) – user692942 May 15 '20 at 10:20

1 Answers1

2

Note that you cannot include VBS in VBA and ExecuteGlobal does not exist in VBA.

So either you run the VBS as an external script:

Shell "wscript c:\null\a.vbs", vbNormalFocus

or you need to re-write the VBScript classes in VBA. Most of the VBA code would not need too much adjustments, but on the other hand a simple copy/paste would not work neither.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73