Solved

Script to Read Excel Files

Posted on 2015-02-13
13
102 Views
Last Modified: 2015-03-18
Hello,

I have a network share with a series of folders and sub folders in it and I am looking for a way in which I can identify and look at each Excel file and when a value in a certain cell is identified it captures the Path of that file?

I am not sure which technology or approach would be best for this or whether this is indeed possible - any help would be great and any example scripts even better. The value I am looking for is always in the same place - on a tab called "Sheet Summary" and in Cell B47.

Thanks in advance

GISVPN
0
Comment
Question by:gisvpn
  • 7
  • 4
13 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40607485
It is possible - see this article about "Reading document properties in multiple files", which shows how to go through a folder and open each spreadsheet in turn.

Instead of looking at the Author property as mentioned in that article

ActiveWorkbook.BuiltinDocumentProperties("Author")

you would probably want

ActiveWorkbook.Sheets("Sheet Summary").cells(47,2)

The rest of the code should work fine for you.
0
 

Author Comment

by:gisvpn
ID: 40607622
Hi Philip,

This works great. Two questions you may be able to help me with.

- this errors out as soon as it hits an excel file where there is no Sheet Summary tab - how can I simply ask it to ignore any spreadsheet where it cannot find the summary tab?
- Do you know how I can capture the full file paths for that file?

I would like to add in Column C: but not sure what I need to put in xx?

mySheet.Cells(introw, 3) = xx?

It looks for strExtension = "*.xls*"  how can I add Xlsx and Xlsm to this too?

Many thanks!

GISVPN
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40607626
>> - this errors out as soon as it hits an excel file where there is no Sheet Summary tab

It shouldn't do if you have the line

On Error GoTo MyError

in.

>> Do you know how I can capture the full file paths for that file?

mySheet.Cells(introw, 1) = strFolder & "/" & strFile

>> I would like to add in Column C: but not sure what I need to put in xx?

mySheet.Cells(introw, 3) = ActiveWorkbook.Sheets("Sheet Summary").cells(47,3)

>> It looks for strExtension = "*.xls*"  how can I add Xlsx and Xlsm to this too?

It already does - that's what the end star * is for. It will look for anything containing .xls; not nessarily just .xls, but .xlsb, .xlsm etc.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:gisvpn
ID: 40607629
Oh I Just noticed that this when it runs DIR does not include subfolders?

strFolder = "C:\test\"

could I amend this to include this folder and all subfolders?
0
 

Author Comment

by:gisvpn
ID: 40607950
Hi Philip - thanks for the post above, the above worked many thanks! Let me know if you can answer the question above on being able to expand the scope of the script to cover sub folders too.
0
 

Author Comment

by:gisvpn
ID: 40614356
hi Phillip - not sure if you can help with the last question on whether you can ensure subfolders are included - would this be something that can be done at all?
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40614434
I've got a few ideas, but they would take some time do.

Basically, you use another DIR to go through the subfolders, and then catalog each of those folders. However, it would take some time to implement.
0
 

Author Comment

by:gisvpn
ID: 40614444
Hi Phillip,

Thanks for the reply - would it take time to execute or time to create a script that would be able to do this?

Regards,

GISVPN
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40614447
Time to create.
0
 

Author Comment

by:gisvpn
ID: 40614585
ok - if you have any suggestions please let me know! This is a key part of the script/requirement - a pity it is not an easy amendment to where the script points!
0
 

Author Comment

by:gisvpn
ID: 40620660
If anyone else can help with this question it would be greatly appreciated. The script offered here is what is required but I would like to know if there is a simpler/better approach to ensure sub folders are in scope of the script too when run.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40672897
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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.

825 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