|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Resident Slacker
Join Date: Dec 2001
Location: Suisun City, California (i know, where the hell is that?!?!?)
Posts: 2,620
|
Visual Basic Runtime Error 1004
Hi everyone,
i'm getting a pain-in-the-@$$ runtime error in an excel macro that has been working fine for a few months (up until last week). here is the code: Private Sub CommandButton2_Click() ' sort Macro ' Macro recorded 9/21/2001 by William Gates ' ' object class problems with in-line code for sort, call for now ' ' Sub listfiles() Dim myfile As String ' Dim master As String Dim fs As Object Dim datev As Date Dim yr As Integer Dim mo As Integer Dim da As Integer Dim myrow As Integer Dim i As Integer Dim myrow6 As Integer Dim mycol As Integer Dim yrmo As String mycol = 1 myrow = 1 myfile = Dir("C:\WINDOWS\Desktop\$Report\0*.xls") 'pattern of files Do Until myfile = "" Workbooks.Open Filename:=myfile yr = Mid(myfile, 1, 2) mo = Mid(myfile, 3, 2) da = Mid(myfile, 5, 2) datev = mo & "/" & da & "/" & yr Windows(myfile).Activate Sheets("Sheet1").Select ActiveSheet.Range("C5:T15").Select Selection.Copy Windows(myfile).ActivateNext Sheets("data").Select ActiveCell.SpecialCells(xlLastCell).Select ActiveCell.Offset(1).Select myrow = ActiveCell.row Worksheets("data").Cells(myrow, 1).Value = datev i = 1 Do Until i = 11 Worksheets("data").Cells(myrow + i, 1).Value = datev i = i + 1 Loop ActiveSheet.Cells(myrow, 3).Select Selection.PasteSpecial Paste:=xlValues, Operation:= _ xlNone, SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False Windows(myfile).Close ' delete the file just used, to prevent operator duplicates. ' rejected idea: delete ONLY in SLO charting, since usu files are the same as for RT ' allows user to completely control adds to either file; always del after use Set fs = CreateObject("Scripting.FileSystemObject") fs.DeleteFile myfile ' get the next file in the Dir, and LOOP back myfile = Dir Loop ' call because of Class problem; ' Sort2 also copies formulas into cols for charts Call sort2 Sheets("Start").Select Range("A8").Select End Sub ok, so this command takes all of the excel spreadsheets in a certain directory, rips the data out, and places the information into the current spreadsheet where reports and analysis's can be run. none of the spreadsheets are actually listed in the macro itself, it just grabs all that start with 0 and uses the data, then deletes the spreadsheets. the error i'm getting is: Run-time error '1004': '020204.xls' (<-or whatever sheet it's looking for) could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted. the file hasn't been moved, as a matter of fact, the only reason that the macro should know it exists is because it's in the directory i assigned. the macro is able to get the retrieve the file name (the 020204.xls is correct) because it is in the assigned directory, but after it sees it it claims it can't be found. what gives? if you need more infor, i'd be happy to provide.
__________________
Friends help you move. REAL friends help you move bodies. - me quite possibly the best book ever written... by me |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|