+ Reply to Thread
Results 1 to 2 of 2

Run-time error 1004 - Cannot copy sheet to new file

  1. #1
    Registered User
    Join Date
    01-14-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    29

    Unhappy Run-time error 1004 - Cannot copy sheet to new file

    Hello, I'm trying to copy, using code, a sheet to another workgroup.
    I make this steps: Create a new file with name "file1.xlsx" and select the "totais" sheet from the "oldfile.xlsx" and when the code do the move command it gives an error : "run-time error 1004: Excel cannot insert the sheets into the destination workbook, because it contains fewer rows and columns than the source workgroup...".
    They advise to copy only the cells that have data.
    My source file has 1048576 rows by 'XFD' columns and the destination only has 65536rows by 'IV' columns.
    i don't know why my source file has so many columns and rows. I don't need them...
    Any help?
    Code:

    If NumTrab = 0 Then 'Se seleccionou TUDO então faz:
    Workbooks.Add
    ActiveWorkbook.SaveAs Filename:=TempFile, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    TempFile = ActiveWorkbook.Name
    Windows(FicheiroActual).Activate
    If Cb_5.Value = True Then 'TOTAIS ANO
    Call TotaisAno
    Sheets("TOTAIS").Move Before:=Workbooks(TempFile).Sheets(1)
    End If
    If Cb_2.Value = True Then 'Horas Trabalhadas
    For x = 0 To UBound(ListaPessoal)
    Nome = ListaPessoal(x, 1)
    Call FazFolhaPessoal(Nome)
    If FolhaInexistente = False Then
    Workbooks(FicheiroActual).Sheets(ListaPessoal(x, 1)).Move After:=Workbooks(TempFile).Sheets(1)
    End If
    Next x
    End If
    If Cb_4.Value = True Then 'Horas de Acerto Mensais
    Call Calcula_HA_Mensal
    Workbooks(FicheiroActual).Sheets("Horas Acerto Mensal").Move Before:=Workbooks(TempFile).Sheets(1)
    End If
    If Cb_3.Value = True Then 'HCI's Mensais
    Call Calcula_HCI_Mensal
    Workbooks(FicheiroActual).Sheets("HCI Mensal").Move Before:=Workbooks(TempFile).Sheets(1)
    End If

    Workbooks(TempFile).Save 'Guarda Ficheiro
    Workbooks(TempFile).Close
    A = MsgBox("Dados gravados com sucesso no ficheiro " & TempFile, vbInformation + vbOKOnly)
    Exit Sub
    End If



    Thank you,

    Mário
    Last edited by mjcordeiro; 06-04-2009 at 09:25 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Run-time error 1004 - Cannot copy sheet to new file

    You need to post the code, remember to use Code Tags
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1