PDA

View Full Version : Copy data



KK1966
07-04-2011, 08:57 PM
Hi all ,

don't know which part by the code below since it was moved from excel 2003 to excel 2007,

Error is
Run Time Error "1004":
excel can't insert the sheets into the destination workbook, because it contains fewer rows and columns than the source workbook .........else.


part of error code here:
.Sheets(1).Copy After:=thisWorkbook.Sheets(thisWorkbook.Sheets.Count)
Sub ImportAll()

Dim folderPath As String
Dim fileName As String
Dim thisWorkbook As Workbook

folderPath = "D:\My Documents\Sample\"

Set thisWorkbook = ActiveWorkbook

If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
fileName = Dir(folderPath & "*.xl*")
Do While fileName <> ""
Workbooks.Open folderPath & fileName
With ActiveWorkbook
.Sheets(1).Copy After:=thisWorkbook.Sheets(thisWorkbook.Sheets.Count)
.Close savechanges:=False
End With
fileName = Dir
Loop

MsgBox "Finished"
Sheets("RunData").Select
End Sub

any one can help or advised
thanks

Kenneth Hobs
07-05-2011, 06:20 AM
Sounds like you are trying to copy a sheet from 2007 to a sheet in 2003 format. Change your xls to an xlsx or xlsm by Save As, close, and reopen to get the maximum number of rows allowed by 2007.