WSH VBScript switch workSHEET in already open Excel workBOOK

Hi Expert,

Is it possible to switch worksheets within a workbook in a WSH VBScript (referenced by name) and if so, how would I do it?

This will be used in a script that already opens an Excel file. I want to access a worksheets called "Version Control".

The following is how I am opening the workbook:

xlsFile = path & "\xml-sitemap.xls"
Set objExcel = WScript.CreateObject("Excel.Application")

Any help on above is really appreciated.
Last updated:6/20/2013 5:39:41 AM

1 Answers

Sumit Kesarwani
Sumit Kesarwani

Hi Takeshi,

This will do it (amended following Ekkehard.Horner's comment)

Dim ws
Dim wb

xlsFile = path & '\xml-sitemap.xls'
Set objExcel = WScript.CreateObject('Excel.Application')
Set wb = objExcel.ActiveWorkbook 'the ActiveWorkbook will refer to the opened workbook
Set ws = wb.Worksheets('Version Control') 'ws is a Worksheet object