473,394 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 .. lastworksheetnumber) do
...operations
end
Claudia

Jun 27 '08 #1
7 2003
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

Jun 27 '08 #2
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

Jun 27 '08 #3
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

Jun 27 '08 #4
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
Jun 27 '08 #5
Well seeing as I am answering it in an Excel group, it seems totally
relevant.

--
__________________________________
HTH

Bob

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP04.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

Jun 27 '08 #6
On Jun 25, 7:09 am, "Bob Phillips" <Bob...@somewhere.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
Jun 27 '08 #7
Il giorno Tue, 24 Jun 2008 14:15:04 -0700, =?Utf-8?B?TWlrZSBI?=
<Mi***@discussions.microsoft.comha 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)
--
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Shawn | last post by:
I have the basics working as is described in KB199841. I currently have my ASP page loading into Excel by setting the ContentType of the page: <%response.ContentType="application/vnd.ms-excel"%> ...
1
by: mr_ocp | last post by:
Hi friends I need routines to create an excel file with worksheets for each customer and a text file as well for each customer, first worksheet would be a "Summary Report", here is the code that...
5
by: Iris | last post by:
I have 8 text files (tab delimited) that I would like to import into an Excel workbook as 8 individual worksheets but I cannot find any example code on this subject. Can anyone help me please???? ...
0
by: dleh | last post by:
I have been tasked with producing a server application that will convert excel files to html. I have no experience of developing under Windows, (but plenty of UNIX/C++ experience) but I picked...
4
by: paul.chae | last post by:
I have a table in Access with about 3000 records. There are ~60 unique values in the ID field for the 3000 records. What I would like to do is automatically generate multiple Excel worksheets...
1
by: J Daniel Melton | last post by:
Hello, I am using late binding in a managed VC++ .NET 2003 application. I used KB 302902 (for C#) as a starting point and converted it to managed C++. I built a managed class that is intantiated...
0
by: SirMikesALot | last post by:
I'm pretty good at Excel, but my skills in Visual Basic are very limited. I found script on-line that creates & opens a user form, allows you to select your worksheets, prints the selected...
4
by: Chris Gilpin | last post by:
Hey everybody. I have Access set up using VBA to run a bunch of queries automatically, and then export the results into Excel. The only problem is, I want each query to be exported to the same...
1
by: MarkDotNet | last post by:
Hi I am trying to switch Excel worksheets in VBA. I get an error saying "subscript out of range". Please Help- Here is code (Fails on last 2 lines- Note that I ommited the recordset portion of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.