• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 114
  • Last Modified:

Script to Read Excel Files

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
gisvpn
Asked:
gisvpn
  • 7
  • 4
1 Solution
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
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
 
gisvpnAuthor Commented:
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
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
>> - 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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
gisvpnAuthor Commented:
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
 
gisvpnAuthor Commented:
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
 
gisvpnAuthor Commented:
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
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
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
 
gisvpnAuthor Commented:
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
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Time to create.
0
 
gisvpnAuthor Commented:
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
 
gisvpnAuthor Commented:
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
 
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now