SkipVought
Programmer
This one has had me stumped all morning.
I can copy the code or export/import the module with the same results:
1. copy the code into a new workbook
2. save the workbook in a folder with several workbooks that all begin with DSC_CBU_Actions_
3. run the code sucessfully. Save and run again.
4. save, close & open the workbook
5. run the code UNSUCESSFULLY
On the statement
I get a run time error 1004: filename could not be found
nothing has changed, except for the workbook being reopened.
Any thoughts?
Skip,
[red]Be Advised![/red] A chicken, who would drag a wagon across the road for 2 cents, is…
POULTRY in motion to PULLET for a PALTRY amount!![[tongue] [tongue] [tongue]](/data/assets/smilies/tongue.gif)
I can copy the code or export/import the module with the same results:
1. copy the code into a new workbook
2. save the workbook in a folder with several workbooks that all begin with DSC_CBU_Actions_
3. run the code sucessfully. Save and run again.
4. save, close & open the workbook
5. run the code UNSUCESSFULLY
On the statement
Code:
Set wb = Workbooks.Open(.Name, , True)
nothing has changed, except for the workbook being reopened.
Code:
Sub CopyData()
Dim oFS, oFolder, oFile, wb, rng As Range, ws As Worksheet
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFS.GetFolder(ThisWorkbook.Path)
For Each oFile In oFolder.Files
With oFile
If .Name Like "DSC_CBU_Actions_*" Then
Set wb = Workbooks.Open(.Name, , True)
With wb
For Each ws In wb.Worksheets
With ws
Set rng = .Columns(1).Find("1")
.Range(rng, .Cells(.UsedRange.Rows.Count, .UsedRange.Columns.Count)).Copy _
Sheet1.Cells(Sheet1.[A1].CurrentRegion.Rows.Count + 1, 1)
End With
Next
wb.Close
End With
End If
End With
Next
Set wb = Nothing
Set oFolder = Nothing
Set oFS = Nothing
End Sub
Skip,
![[glasses] [glasses] [glasses]](/data/assets/smilies/glasses.gif)
POULTRY in motion to PULLET for a PALTRY amount!
![[tongue] [tongue] [tongue]](/data/assets/smilies/tongue.gif)