?
Solved

Opening several workbooks

Posted on 2013-12-13
6
Medium Priority
?
202 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
[X]
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
  • 3
  • 2
6 Comments
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 1000 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 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

762 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