Hi GTO,
What I am trying to do is open all the files in a given folder, and copy the entire contents from a given sheet, in each workbook, say "ABC" for arguments sake, and paste the values into sheet "DEF" in my active workbook.
the code is as follows:
Sub ImportInbound()
Dim Pth As String
Dim MyFile As String
Dim msg As String
msg = "Warning: Import External Data?" & vbNewLine & _
vbNewLine & "Select OK to continue, or Cancel to exit"
If MsgBox(msg, vbOKCancel) = vbCancel Then Exit Sub
Application.ScreenUpdating = False
Pth = "C:\Documents and Settings\DAVES\Desktop\TEST\"
MyFile = Dir(Pth & "*.xls")
Do Until MyFile = ""
Call AppendInbound(Pth, MyFile)
MyFile = Dir
Loop
End Sub
Sub AppendInbound(Pth As String, MyFile As String)
Dim NewWB As Workbook
If Not MyFile Like "*Main.xls" Then
Set NewWB = Workbooks.Open(Pth & MyFile)
NewWB.Sheets(1).Range(NewWB.Sheets(1).Range("C11"), NewWB.Sheets(1).Range("S65536").End(xlUp)).Copy
ThisWorkbook.Sheets(1).Range("C65536").End(xlUp).Offset(1).PasteSpecial xlValues
Application.CutCopyMode = False
NewWB.Close False
End If
End Sub
It seems to open the files in say Folder1, copying the contents of "ABC", however it falls when it hits:
ThisWorkbook.Sheets(1).Range("C65536").End(xlUp).Offset(1).PasteSpecial xlValues
Regardless, of whether or not I specify the sheet name of sheet number, the same problem occurs.