Open A Excel File using VBScript @ Windows Script Host


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 words
Last Post: Happy Valentine's Day, another heart equation
Next Post: Variable Scopes in VBScript at Windows Script Host

The Permanent URL is: Open A Excel File using VBScript @ Windows Script Host

One Response

  1. Lucas

Leave a Reply