Open Multiple files across a internal network
Hello I'm new to this forum and also this is my first time ever asking a question online. Just some quick back round, I write relativity simple macros for colleagues to analyze engineering data in one of the largest companies in the world, I must be careful about what I say here because our information is very sensitive so I must apologize if some of my questions are some what vague. Problem statement: First of all we have recently "upgraded" to windows 2010 and my programming experience is mainly in C and Pearl. I need to open multiple files one at a time across an internal network, it's not uncommon to open 100 +. Because the file names are very specific I usually have the user list the files in column "A". example of my macro: 1. Anayzle one iteration name in column A at a time: 2. Set a variable for the path to the given iteration. 3. Set variable paths to the files i want from that iteration, usually done by drop down boxes the user selects. 4. Open all the files I want in the given iteration. 5. Run my code on the files 6. Close the files then go to the next iteration. Example MYPath = "http://*.**.***.**/ascii_data/vegas_pack/" & det & "/" & iter & "/" & iter MYCSV = MyPath & "_yield.csv" 'Note not all ways a csv usually ~1/5th the data Workbooks.OpenText Filename:=MYCSV, DataType:=xlDelimited, comma:=True, Space:=False 'My code to analyze data here close file Excel never has an issue opening the first few files, but after that it just stops seeing the files and errors out, it never makes it past 10 iterations before errors occur. The error I receive basicly says "1004 file does not exists", although the file does exist. What I have tried: -Built sleep commands - didn't work -If code errors out, try to open the file multiple times then move on. -didn't work -This does work however very annoying, I have the code sleep 40 ms then try multiple times to open the file and if the err code is still 1004 and it just about always is then give me a message box that says "This is the annoying button push ok" Then excel downloads the file and we do it again. So I have to sit there and push ok hundreds of times :( I have used this code to open files with all other excel versions and never had this issue, just 2010. Sorry for the long winded problem statement, any help would be greatly appreciated. Ryan
August 5th, 2011 11:10am

Macro? What language are you using? Talk to me now on
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 12:06pm

I can give few suggestions with respect to this : 1) To loop over the files , you can use the for each enumerator in SSIS control flow. For information on this and configuration : http://msdn.microsoft.com/en-us/library/ms169800.aspx . This is when you don’t have the file paths stored in a table. 2) But , as mentioned above that the files locations are stored in a column in a table , first the column values have to be read using a for each loop ADO enumerator by which the file path can be read into a variable. 3) Use the variable above to open the file using the C# in script task : using System.IO; FileStream fileStream = new FileStream(@<<variable from for each ADO enumerator>>, FileMode.Open); try { Perform any operations. // read from file or write to file } finally { fileStream.Close(); } Happy to help! Thanks. Regards and good Wishes, Deepak. In a revamp of my Blog!
August 5th, 2011 12:40pm

Thank you I'll give it a try
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 1:24pm

Sorry VBA
August 5th, 2011 1:25pm

This is an SQL Server Integration Services forum - are you looking to use SSIS instead of VBA to accomplish this task? Or are you looking to fix your VBA code? If it's the latter, this isn't the place for you to ask your question. If it's the former, please try Deepak's suggestions - but keep in mind that using the Office COM API in an SSIS Script Task isn't supported. Talk to me now on
Free Windows Admin Tool Kit Click here and download it now
August 5th, 2011 1:48pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics