Windows Vista Forums

RE: How to do something in an VBS script for all worksheets of an Exce
  1. #1


    Mike H Guest

    RE: How to do something in an VBS script for all worksheets of an Exce

    Hi

    Sub sonic()

    for x=1 to worksheets.count
    worksheets(x).select
    'do your stuff
    next

    end sub


    depemding on what you are doing you may not (probably won't) need to select



    Mike

    "Claudia d'Amato" wrote:

    > I would like to do something in a *.vbs script and all the operations should be applied
    > on each worksheet within an Excel file.
    >
    > How do I do this?
    >
    > It must be something like:
    >
    > for i in (1 .. lastworksheetnumber) do
    > ...operations
    > end
    >
    >
    > Claudia
    >
    >

      My System SpecsSystem Spec

  2. #2


    Reventlov Guest

    Re: How to do something in an VBS script for all worksheets of an Exce

    Il giorno Tue, 24 Jun 2008 14:15:04 -0700, =?Utf-8?B?TWlrZSBI?=
    <MikeH@xxxxxx> ha scritto:

    >Sub sonic()
    >for x=1 to worksheets.count
    >worksheets(x).select
    >'do your stuff
    >next
    >end sub
    I'm not sure if this works with already opened worksheets. If it's not, you have to open
    every single xls before working on it.

    Set xl=CreateObject("excel.application")
    xl.Visible=True

    'xl.Workbooks.Open Filename

    for x=1 to xl.worksheets.count
    xl.worksheets(x).select
    'do your stuff
    next


    If you want to run an existing xls macro from a vbs:

    filePath = "c:\Test.xls"
    Set oExcel = CreateObject("Excel.Application")
    oExcel.Workbooks.Open(filepath)
    oExcel.Run "macro1"
    oExcel.ActiveWorkbook.Save
    oExcel.ActiveWorkbook.Close
    oExcel.Quit
    Set oExcel = Nothing



    --
    Giovanni Cenati (Bergamo, Italy)
    Write to "Reventlov" at katamail com
    http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
    --

      My System SpecsSystem Spec

RE: How to do something in an VBS script for all worksheets of an Exce problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyway to add worksheets on loop RICK VB Script 1 14 Oct 2008
Re: How to do something in an VBS script for all worksheets of an Excel file? Cor Ligthert[MVP] VB Script 4 25 Jun 2008
RE: How to do something in an VBS script for all worksheets of an Exce RyanH VB Script 0 24 Jun 2008
Excel 2007/ Vista- Problem Duplicating Worksheets Within Same Work Robert M Vista General 3 17 May 2008
Accept terms & conditions message for Excel worksheets MeasureMe Vista General 6 28 Mar 2007