Code looping through files new line
Hello again,
Otto and I have talking this morning and here are some clarifications about
what we have discovered.
first the source of my files are from a mainframe which saves as a csv file
and I open it in MS Excel. Once opened I save it as an Excel .xls file and
download it to my computer. All the files that we've been dealing with are
of this nature.
Otto has asked me to document the downloading process for these files and
post them here in case we have a issue with the excel files. I will repost
after this evening to see if I can document the process and recreate the
issues. If I cant' recreate then it will have to be in the initial files
that were saved in excel. If I do recreate the problem I'll return and ask
for more advice. I tryly appreciate all of you for sticking by and trying to
help me out.
Thanks
Bob Reynolds
Next Otto asked me to clean out the folder and then create new .xls files
(blank) and save them in the directory. The names were Book (1) (2) etc... I
have six of those files placed in the folder and we discovered there was no
problems with the opening and closing of the files. Otto gave me Debra's
maco from her werbsite and all seems well at this time.
"rjr" wrote in message
.. .
Started new here, the others are getting pretty deep.
OK, Have tried using this with several different issues this morning.
Here's the outcome.
I used the F8 to step through it and see what was happening and also just
ran the code and let her rip.
I got several messages regarding the files weren't processed, using the
full code. and I got a couple there were processed.
then using the test code Tom wanted me to last night that worked, I got
the first two didn't work, but the rest did as they were supposed to,
opened the file and made the specific changes and closed the fiel.
The first two files weren't opening as they should and I then opened them
both manually and they opened and looked fine, and then I closed them out.
They are the first two in alphabetical order.
I then changed the order and was able to get two of the 22 to open. The
others seemed to hang on
et wb = Workbooks.Open(fl.Path)
and then went to the error. I've got to go to work today and will try new
files, but it would seem to me that if one or more works properly then
something in the file would be the problem. Unfortunately all files were
saved the same way and all were exported to excel in csv format, the files
were opened and then saved as in xls format.
Is there a need to put a slight pause into the code that when it attempts
to start opening the file it would pause and make sure the file had enough
time to open, or am I asking a stupid thing???
Thanks again
Bob Reynolds
Sub AllFiles()
Dim sFol As String
Dim fso As Object, fl As Object
Dim fld As Object
Dim wb As Workbook
sFol = "C:\temp"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(sFol)
For Each fl In fld.Files
if lcase(fl.Path) < lcase(thisworkbook.Fullname) then
If fl.Name Like "*.xls" Then
On Error Resume Next
Set wb = Workbooks.Open(fl.Path)
if err.number = 0 then
MsgBox wb.FullName
wb.Close
else
msgbox "Not processed: " & fl.Path
err.Clear
end if
On Error goto 0
End If
End if
Next
End Sub
|