Sunday, August 10, 2008

Re-using VBS code

Last week, I wanted to call VBS file into another VBS file. I wanted similar way in other languages like below.
In C++ -> Header file -> include <*.h>
In VB -> Modules (*.bas)
In Java -> Packages -> import com.myLayer.*

Basically I wanted to make it as a library. I am writing the functions to get the data from Excel and PPT. I have to create separate VBS file for each requirement. Few functions are common for all the VBS files. I got a help from visualbasicscript site. Post: Include VBS file in other files

VBScript code - To Import VBS Library

' Method : ImportVBSLibrary
' Author : T. Palani Selvam
' Purpose : To import all vbs code from library file.
' Parameters: sFileName - String, contains the VBS functions
' Returns : VBS code
' Caller : - Nil
' Calls : - Nil
Function ImportVBSLibrary(sFileName)
Dim ObjFSO,ObjFile
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjFile=ObjFSO.OpenTextFile(sFilename,1)
Set ObjFile = Nothing
Set ObjFSO = Nothing
End Function

ExecuteGlobal ImportVBSLibrary("D:\myscripts\tools\pal_lib.vbs")

No comments: