• 0
Sign in to follow this  
Jéssica De Moura Lima

Importar dados de arquivo externo


Boa noite!

Entendo muito pouco de VBA e gostaria de importar dados de um arquivo externo, mas o meu código não está funcionando.


Sub Importar()


Dim Abrir As String
Dim Importarwb As Workbook
Dim Importarguia As Worksheet


Abrir = Application.GetOpenFilename( _
FileFilter:="Arquivo do Excel (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="Escolha o arquivo a ser importado")

Set Importarwb = Application.Workbooks.Open( _
Filename:=Abrir, Password:="123")

Set Importarguia = Importarwb.Worksheets(1)

Application.ScreenUpdating = False

'Desbloquear guia e pasta de trabalho
ThisWorkbook.Unprotect ("123")
ActiveSheet.Unprotect ("123")

'Copiar dados

'Limpar guia "Relatório" e colar dados

With Worksheets("Relatório")
    .Visible = True
    .Range(.Cells(1, 1), .Cells(10000, 90)).ClearContents
    .Visible = False
End With

'Fechar arquivo externo

'Bloquear guia e pasta de trabalho
ThisWorkbook.Protect Password:="123", Structure:=True, Windows:=False

Sheets("Base de Contratos").Protect Password:="123", _
    DrawingObjects:=True, _
    Contents:=True, _
    Scenarios:=True, _
    UserInterfaceOnly:=True, _
    AllowFormattingCells:=False, _
    AllowFormattingColumns:=False, _
    AllowFormattingRows:=True, _

    AllowInsertingColumns:=False, _
    AllowInsertingRows:=True, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=True, _
    AllowSorting:=False, _
    AllowFiltering:=True, _

Application.ScreenUpdating = True

MsgBox "Relatório importado com sucesso!"

End Sub


Alguém poderia me ajudar?

Share this post

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this