LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Opening some workbooks with a Macro renames them

I have a macro which opens and reads about 90 workbooks in a
directory. There a 5 workbooks out of the 90 which, when opened,
rename themselves by appending a digit to the end of the workbook
name.

That is:
070218 Fred Smith.xls
gets opened as
070218 Fred Smith1.xls

I can't see what is different about these 5 out of 90, which will not
allow them to be opened without renaming. If I open them manually, I
don't have this problem.

The code is:

X = "070218"

With Application.FileSearch
.NewSearch
.LookIn = ProcessedFolder
.Filename = x & "*.XLS"
.SearchSubFolders = False
.Execute

For i = 1 To .FoundFiles.Count

For Each r In Range("A2:A500") 'This is a range in another
workbook .. this is working OK
If Trim(r) < "" Then 'Process only non-blank cells
If InStr(.FoundFiles(i), r) 0 Then
Workbooks.Open .FoundFiles(i), ReadOnly:=True
wbfilename = Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") +
1, 200)
Application.StatusBar = "Processing " & wbfilename
r.Offset(0, 2) = Workbooks(wbfilename).Sheets("Charge
Sheet").Range("CS_ThisVersion").Value '<=== Fails here with Error 9
- Subscript out of Range
Workbooks(wbfilename).Close SaveChanges:=False
End If
End If
Next r
Next i
End With

The macro fails at
r.Offset(0, 2) = Workbooks(wbfilename).Sheets("Charge
Sheet").Range("CS_ThisVersion").Value
... with a subscipt out of range error (because the wbfilebame
variable is no longer the same as the short file name due to the
renaming).

Does anyone know what would force a spreadsheet to open renamed? I
happens to the same 5 workbooks, so I think it is file attribute or
file name related but my investigations don't show any obvious
differences.


Greg

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Until macro that renames workbooks and keeps the original workbook open [email protected] Excel Programming 2 February 13th 06 01:42 AM
DFS RENAMES MS EXCEL FILES TO ALFANUMERIC!!! Bill Excel Discussion (Misc queries) 6 August 22nd 05 09:25 PM
Opening Multiple Workbooks from a macro with a twist Doug Excel Programming 2 December 16th 04 08:05 PM
run macro on opening of workbooks shaharul[_3_] Excel Programming 0 September 16th 03 02:48 AM
SaveAs problem, renames Worksheet too E.Anderegg Excel Programming 2 July 29th 03 02:54 AM


All times are GMT +1. The time now is 10:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"