Solved

Opening several workbooks

Posted on 2013-12-13
6
162 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
Comment Utility
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
Comment Utility
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
Comment Utility
If the oldest does not have the EMPID do I close it
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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
Comment Utility
Can I get a code example

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

Expert Comment

by:rspahitz
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now