Importar um arquivo XLS para um outro arquivo do excel via VBA

0 respostas
T

preciso fazer uma macro no excel que abra uma caixa de dialogo, eu escolha o arquivo do excel desejado e, ao abrir, importasse para o proprio arquivo q estou trabalhando.

pra especificar melhor..eu tenho um codigo q faz quase isso..mas nao sei onde eu posso modificar.

alguem pode ajudar

Dim DestBook As Workbook, SourceBook As Workbook
    Dim DestCell As Range
    Dim RetVal As Boolean

    ' Turn off screen updating.
    Application.ScreenUpdating = False

    ' Set object variables for the active book and active cell.
    Set DestBook = ActiveWorkbook
    Range("A1").Activate
    Set DestCell = ActiveCell
        
    ' Show the Open dialog box.
    RetVal = Application.Dialogs(xlDialogOpen).Show("*.xls")

    ' If Retval is false (Open dialog canceled), exit the procedure.
    If RetVal = False Then Exit Sub

    ' Set an object variable for the workbook containing the text file.
    Set SourceBook = ActiveWorkbook

    ' Copy the contents of the entire sheet containing the text file.
    Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Copy

    ' Activate the destination workbook and paste special the values
    ' from the text file.
    DestBook.Activate
    DestCell.PasteSpecial Paste:=xlValues

    ' Close the book containing the text file.
    SourceBook.Close False
Criado 3 de dezembro de 2010
Respostas 0
Participantes 1