How to do something in an VBS script for all worksheets of an Excel file?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Claudia d'Amato

    How to do something in an VBS script for all worksheets of an Excel file?

    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 .. lastworksheetnu mber) do
    ...operations
    end


    Claudia

  • =?Utf-8?B?RlN0MQ==?=

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

    hi
    something like this might work...
    Sub claudia()
    For i = 1 To Worksheets.Coun t
    Worksheets(i).R ange("A1").Inte rior.ColorIndex = 6
    'above is for test only
    Next i
    End Sub

    regards
    FSt1


    "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 .. lastworksheetnu mber) do
    ...operations
    end
    >
    >
    Claudia
    >
    >

    Comment

    • =?Utf-8?B?TWlrZSBI?=

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

      Hi

      Sub sonic()

      for x=1 to worksheets.coun t
      worksheets(x).s elect
      '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 .. lastworksheetnu mber) do
      ...operations
      end
      >
      >
      Claudia
      >
      >

      Comment

      • =?Utf-8?B?Unlhbkg=?=

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

        This should be nice and easy for you.

        Dim sh As Worksheet

        For Each sh In Worksheets
        'your code here
        Next sh

        Hope this helps!
        --
        Cheers,
        Ryan


        "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 .. lastworksheetnu mber) do
        ...operations
        end
        >
        >
        Claudia
        >
        >

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: How to do something in an VBS script for all worksheets of an Excel file?

          I would like to do something in a *.vbs script and all the operations should
          be applied
          on each worksheet within an Excel file.

          As you can tell me what this has to do with VB for Net, then I agree with
          you.

          Cor


          Comment

          • Bob Phillips

            #6
            Re: How to do something in an VBS script for all worksheets of an Excel file?

            Well seeing as I am answering it in an Excel group, it seems totally
            relevant.

            --
            _______________ _______________ ____
            HTH

            Bob

            "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
            news:%23eluoFr1 IHA.3968@TK2MSF TNGP04.phx.gbl. ..
            >I would like to do something in a *.vbs script and all the operations
            >should be applied
            on each worksheet within an Excel file.
            >
            As you can tell me what this has to do with VB for Net, then I agree with
            you.
            >
            Cor
            >

            Comment

            • Chris Dunaway

              #7
              Re: How to do something in an VBS script for all worksheets of anExcel file?

              On Jun 25, 7:09 am, "Bob Phillips" <Bob...@somewhe re.comwrote:
              Well seeing as I am answering it in an Excel group, it seems totally
              relevant.
              >
              Yes, but the person who posted the question, cross posted it to
              the .Net group where it is off topic. I think Cor was requesting that
              you remove the .Net group from the follow up.

              Cheers,

              Chris

              Comment

              • Reventlov

                #8
                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@discussi ons.microsoft.c omha scritto:
                >Sub sonic()
                >for x=1 to worksheets.coun t
                >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.applica tion")
                xl.Visible=True

                'xl.Workbooks.O pen Filename

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


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

                filePath = "c:\Test.xl s"
                Set oExcel = CreateObject("E xcel.Applicatio n")
                oExcel.Workbook s.Open(filepath )
                oExcel.Run "macro1"
                oExcel.ActiveWo rkbook.Save
                oExcel.ActiveWo rkbook.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)
                --

                Comment

                Working...