Consulting

Results 1 to 2 of 2

Thread: Copy data

  1. #1
    VBAX Contributor
    Joined
    Jun 2008
    Posts
    169
    Location

    Copy data

    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)
    [VBA]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[/VBA]

    any one can help or advised
    thanks

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •