Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Iterate though sheets in external workbook

Posted on 2011-02-17
3
283 Views
Last Modified: 2012-06-27
Trying to run a for each loop on an external workbook with variable number of sheets.

for each wkSht in Workbooks(startFolder).Worksheets
  msgbox("TEST")
next

Open in new window


Not sure why it won't work. startFolder is my absolute path to the workbook, as in C:/book.xls

Still new to VBA and I know this is simple. Please help!

Thanks!
0
Comment
Question by:keats88
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 125 total points
ID: 34919737
Try this

Sub Sample()
    Dim wb As Workbook
    Dim wkSht As Worksheet
    
    Set wb = Workbooks.Open("C:\MyFile.xls")
    For Each wkSht In wb.Worksheets
      MsgBox wkSht.Name
    Next
End Sub

Open in new window


Sid
0
 

Author Comment

by:keats88
ID: 34920032
That works, but is there a way to do this without having to actually open the workbook?

Thanks!
0
 
LVL 30

Assisted Solution

by:SiddharthRout
SiddharthRout earned 125 total points
ID: 34920048
No that I know of... AFAIK, You have to open the workbook.

Sid
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question