Solved

Iterate though sheets in external workbook

Posted on 2011-02-17
3
282 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

821 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