Ir para conteúdo
Fórum Script Brasil
  • 0

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


thur

Pergunta

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 não sei onde eu posso modificar.

alguém 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

Editado por kuroi
Adicionar tag CODE
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...