How to call a particular Sub/Function from one vbs file to other vbs file.
Question ID: 105820
0
0

For Example…
If i have two vbs files named, File1.vbs and File2.vbs

In File1.vbs there are two sub/function as hello(), welcome() and
In File2.vbs there is sample() is a function…
Now i want to call the sub welcome() from File1.vbs into File2.vbs sample() function.

Marked as spam
Posted by (Questions: 7, Answers: 8)
Asked on January 16, 2015 9:20 am
953 views
Answers (2)
4
Private answer

Hello Ahmed,

Yes it is possible to call any sub procedures from one vbs to other vbs file
It is possible using ''ExecuteGlobal'' Statement

Below is the demo code ..

The contents of Demo1.vbs

SUB A()
MsgBox ''SUB A CALLED''
END SUB

SUB B()
MsgBox ''SUB B CALLED''
END SUB

Now as in your question if i need to call Sub procedure B()
It can de done by the following code

'Demo2.vbs

Dim fsObj
Dim vbsFile
Dim myFunctionsStr
Set fsObj = CreateObject(''Scripting.FileSystemObject'')
Set vbsFile = fsObj.OpenTextFile(''C:Demo1.vbs'', 1, False)
myFunctionsStr = vbsFile.ReadAll
vbsFile.Close
Set vbsFile = Nothing
Set fsObj = Nothing
ExecuteGlobal myFunctionsStr
B() ' You can call the required Sub Procedure from Demo1.vbs

Marked as spam
Posted by (Questions: 4, Answers: 2)
Answered on January 16, 2015 11:50 am
0
Private answer

Thank You Rajesh

Marked as spam
Posted by (Questions: 7, Answers: 8)
Answered on January 16, 2015 11:57 am
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top