PC Review


Reply
Thread Tools Rate Thread

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

 
 
Claudia d'Amato
Guest
Posts: n/a
 
      24th Jun 2008
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

 
Reply With Quote
 
 
 
 
FSt1
Guest
Posts: n/a
 
      24th Jun 2008
hi
something like this might work...
Sub claudia()
For i = 1 To Worksheets.Count
Worksheets(i).Range("A1").Interior.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 .. lastworksheetnumber) do
> ...operations
> end
>
>
> Claudia
>
>

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      24th Jun 2008
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
>
>

 
Reply With Quote
 
RyanH
Guest
Posts: n/a
 
      24th Jun 2008
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 .. lastworksheetnumber) do
> ...operations
> end
>
>
> Claudia
>
>

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      25th Jun 2008
Hi guy/girls

It seems that there is somebody active in the newsgroups who is trying to
disturp a lot, by creating a special kind of follow up.

Will you be so kind to stop replying to this person, speaking here from the
dotnet language newsgroup.

We are very interested in scripting, excel or whatever.

But when we want that information we visit those news groups.

Thanks in advance

Cor

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      25th Jun 2008
This seems a tad OTT. What is wrong with this question?

--
__________________________________
HTH

Bob

"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:04408652-2D8E-46F6-A228-(E-Mail Removed)...
> Hi guy/girls
>
> It seems that there is somebody active in the newsgroups who is trying to
> disturp a lot, by creating a special kind of follow up.
>
> Will you be so kind to stop replying to this person, speaking here from
> the dotnet language newsgroup.
>
> We are very interested in scripting, excel or whatever.
>
> But when we want that information we visit those news groups.
>
> Thanks in advance
>
> Cor



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      25th Jun 2008
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


 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      25th Jun 2008
Well seeing as I am answering it in an Excel group, it seems totally
relevant.

--
__________________________________
HTH

Bob

"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>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
>



 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      25th Jun 2008
On Jun 25, 7:09 am, "Bob Phillips" <Bob...@somewhere.com> wrote:
> 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
 
Reply With Quote
 
Reventlov
Guest
Posts: n/a
 
      26th Jun 2008
Il giorno Tue, 24 Jun 2008 14:15:04 -0700, =?Utf-8?B?TWlrZSBI?=
<(E-Mail Removed)> 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)
--
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do something in an VBS script for all worksheets of an Excel file? Claudia d'Amato Microsoft Excel Programming 12 26th Jun 2008 10:53 PM
How to do something in an VBS script for all worksheets of an Excel file? Claudia d'Amato Microsoft VB .NET 9 26th Jun 2008 10:53 PM
Outlk 2k3 Script: Saving Excel File programticaly from OUTLOOK SCRIPT news.microsoft.com Microsoft Outlook VBA Programming 3 22nd Nov 2006 03:33 PM
Weird problem with Excel 2000...Worksheets disappearing in a shared Excel file BrianL_SF Microsoft Excel Misc 2 10th Oct 2006 08:27 PM
Weird problem with Excel 2000...Worksheets disappearing in a shared Excel file BrianL_SF Microsoft Excel Discussion 4 7th Oct 2006 08:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:46 PM.