0

I have written a library in VBScript.

Now I would like to use it in another VBScript, but am not sure of the syntax.

How do I load my library given that its path is:

C://User/My Documents/VBlib.vbs

Normaly to load a class from an external library I would do:

Set OutlookApp = CreateObject("Outlook.Application")

To my understanding one of the possible solutions is to add my library to object reference library but by library has wrong file extension for that.

sgp667
  • 1,797
  • 2
  • 20
  • 38

1 Answers1

1

I tend to use ExecuteGlobal as a way of including function libraries I've written to other vbs files. I wrap it in a function called IncludeFile like this and add the function to the bottom of my vbscript, then use it to 'add' my function libraries:

IncludeFile "\\path\to\my\library.vbs"

'... vbscript here can call any functions belonging to the library


' so long as this function is in the script at the end, anyway
Function IncludeFile(ByVal oFunctionLib)
    Dim oFso : Set oFso = CreateObject("Scripting.FileSystemObject")
    Dim oLibrary : Set oLibrary = oFso.OpenTextFile(oFunctionLib, 1, False)
    Dim sFunctions : sFunctions = oLibrary.ReadAll
    oLibrary.Close
    Set oLibrary = Nothing
    Set oFso = Nothing
    ExecuteGlobal sFunctions
End Function
Dave
  • 4,328
  • 2
  • 24
  • 33