Jump to content

copiar para folha xls


luishmafernandes
 Share

Recommended Posts

Experimenta este....

Sub Test()

' Portugal-a-Programar

MsgBox "Clicar OK para aceder ao explorer."



    Dim wbSource As Excel.Workbook
    Dim wsSource As Worksheet
    Dim wsOutput As Worksheet
    Dim strSelectedFile As String
    Dim outputrow As Long
    
    
    Const strOutputSheet As String = "Sheet1"
    
    Set wsOutput = ThisWorkbook.Worksheets(strOutputSheet)
    strSelectedFile = Application.GetOpenFilename()
    
    'Se cancelado a selecção do ficheiro então sair do processo
    
    If strSelectedFile = "False" Then
        Exit Sub
    End If
    
    Set wbSource = Workbooks.Open(strSelectedFile)
    
    outputrow = 1
    For Each wsSource In wbSource.Worksheets
        wsSource.UsedRange.Copy
        With wsOutput
            .Range("A" & outputrow).PasteSpecial xlPasteAll
        End With
        
        outputrow = outputrow + wsSource.UsedRange.Rows.Count
    Next
    
    wbSource.Close False
End Sub
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.