Windows Script Host (WSH) is powerful. Every windows since Win95 come with default installation of WSH and two languages are supported, JScript (Microsoft’s implementation of Javascript) and VBScript.
Creating Automation Objects is easy. In VBScript, the syntax would be to use CreateObject function and in JScript it corresponds to new ActiveXObject function.
The below is a sample script in VBScript to open an excel file and bring the Excel Application to front.
1 2 3 4 5 6 7 8 9 10 11 12 13 | ' codingforspeed.com Dim fso: Set fso = CreateObject("Scripting.FileSystemObject") ' directory in which this script is currently running CurrentDirectory = fso.GetAbsolutePathName(".") Dim csv: csv = fso.BuildPath(CurrentDirectory, "sample.csv") Dim Excel Set Excel = CreateObject("Excel.Application") Excel.Application.Visible = True Excel.WorkBooks.Open csv ' App Activate, bring to front CreateObject("WScript.Shell").AppActivate Excel.Name |
' codingforspeed.com Dim fso: Set fso = CreateObject("Scripting.FileSystemObject") ' directory in which this script is currently running CurrentDirectory = fso.GetAbsolutePathName(".") Dim csv: csv = fso.BuildPath(CurrentDirectory, "sample.csv") Dim Excel Set Excel = CreateObject("Excel.Application") Excel.Application.Visible = True Excel.WorkBooks.Open csv ' App Activate, bring to front CreateObject("WScript.Shell").AppActivate Excel.Name
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
181 wordsloading...
Last Post: Happy Valentine's Day, another heart equation
Next Post: Variable Scopes in VBScript at Windows Script Host
Thanks, i used this code and worked. But i want my directory be a variable created by time update. How could work?