Solved

Opening several workbooks

Posted on 2013-12-13
6
178 Views
Last Modified: 2013-12-16
Using vba and Excel - I may have 5 workbooks where I need to find Emp ID in the oldest workbook even though it may be in several workbooks.   What is the best way to approach this?
0
Comment
Question by:leezac
  • 3
  • 2
6 Comments
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 250 total points
ID: 39717196
Hi,

Determine the "oldest" workbook (by gaining either the "Date Created" or "Date Last Modified" of each) of the five workbooks, & then open just the workbook with the earliest date (depending what your definition of "oldest" will be).

Then search that single workbook for the "Emp ID" required.

You may have to determine what the course of action will be if two (or more) files share the same "oldest" date.

BFN,

fp.
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 250 total points
ID: 39717239
Yes, for only 5 workbooks, the brute force method is probably best if it's a one-time operation.
If you need to do this over and over, you'll need a macro to check timestamps of the files, open them, search and (if needed) close and repeat for the next oldest.  When done it should either send a message telling you which file contained the item or tell you that the item was not found.
There are some other strategic issues with this, like telling the macro where to find the workbooks (especially if they're not in a fixed location) and what if they timestamp updates...do you want the one that was CREATED earliest, or MODIFIED earliest? And there may be some other things, like is the EMP id on a fixed page ("Sheet1" or would you need to search every sheet in the workbook?  Will the cell contain the exact number or will it be mixed with other things, etc.
0
 

Author Comment

by:leezac
ID: 39717245
If the oldest does not have the EMPID do I close it
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 22

Expert Comment

by:rspahitz
ID: 39717256
That's up to you, but that would probably make sense, especially if you increase from 5 to a dozen or more workbooks.
0
 

Author Comment

by:leezac
ID: 39717267
Can I get a code example

is this a do while or if then else>>
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 39721719
I can't create the exact code on my current system, but see if this helps...

Dim strFileName as String
strFileName = Dir("*.xls")
Do
   ProcessExcelFile(strFileName)

   strFileName = Dir
Loop strFileName <> ""

...

Open in new window

Sub ProcessExcelFile(FileName as String)
   Dim xlFile as WorkBook
   xlFile.Open(FileName)
   '...
   xlFile.Close
End Sub

Open in new window


Again, this may not be exact, but should be somewhat close...the harder part is working with the opened file to dig in and check all the pieces, since you'll have to examine the workbook's sheet's cell's content.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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