WSH VBSCRIPT SWITCH WORKSHEET IN ALREADY OPEN EXCEL WORKBOOK

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
 1572  View(s)
Ratings:
Rate this:
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")
objExcel.Workbooks.open(xlsFile)

Any help on above is really appreciated.
  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: WSH VBScript switch workSHEET in already open Excel workBOOK

    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")
    objExcel.Workbooks.open(xlsFile)
    Set wb = objExcel.ActiveWorkbook 'the ActiveWorkbook will refer to the opened workbook
    Set ws = wb.Worksheets("Version Control") 'ws is a Worksheet object

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!