Originally Posted by
TSparlin
Wow! That was fast. When I run the macro, I receive the following error message before the process completes:
Run time error "1004"
Excel cannot open the file '~$Combine.xlsm' because the file format or file extension is not valid. Verfiy that the file has not been corrupted and that the file matches the format of the file.
The file named "Combine" is the Excel file that I created to house the macro. When I tried to get out of it, it made me save it as a "macro-enabled worksheet".
When I debug, the follow code is highlighted:
Set WB = Workbooks.Open(fsoFil.Path, False)
In the end, it looked like it worked because all of the files were combined onto one tab with correct names. Just the error message thing. Please give me your thoughts. Thanks.
Todd
Hi there,
I am unable to test currently, but by my reckoning, I believe you could fix the error by several different methods.
- Move the Combine.xlsm file and update the path to the correct folder. A simple way would be to move it one folder up in the hierarchy. By example:
Let's say the files (and Combine.xlsm) are currently in C:\Data\MyFiles\
Move Combine.xlsm to C:\Data\ and append Path like:
[VBA]Path = .Path & "\MyFiles\"[/VBA]
[VBA]On Error Resume Next
Set WB = Workbooks.Open(fsoFil.Path, False)
On Error GoTo 0[/VBA]
- Include the "temp file"* with a test:
[VBA]If Mid(fsoFil.Name, InStrRev(fsoFil.Name, ".") + 1) Like "xls*" _
And Not fsoFil.Name = .Name _
And Not fsoFil.Name = "~$" & .Name Then
'OR...
If Mid(fsoFil.Name, InStrRev(fsoFil.Name, ".") + 1) Like "xls*" _
And Not fsoFil.Name = .Name _
And Not fsoFil.Name Like "*" & .Name Then[/VBA]
Of those, I personally would probably just move the file and append the Path, it just seems most assured and easy. If you want to keep the file (sorry, workbook) in with the ones being ripped from, I would try the last suggestions (include checking for the temp name in the IF), and specifically, the first of these two if there may be another file in the folder with a filname ending in Combine.
I personally try and avoid ignoring errors, unless I know what the exact error will be and can use that error to tell me something (like if a certain workbook is not open that should be). I suppose we do know the exact error to expect, but I would just try the other methods first.
* - Clarication Sought?
Hi all,
Just in case anyone has a moment to expound (and or correct me) on this, my belief is that the ~$name is a temp file in memory, right? I notice that on the PC I am at, when I open Todd's wb (or other wb's), I don't see this in Explorer?!? I still see .doc's if I have them open. Todd's system obviously must be able to see these. I tested both a wb on a flash drive or a network drive. Any ideas?