VBA to Open Excel File and Paste Sheet 1 Data into “RRimport” Sheet in Current Workbook

前端 未结 1 594
有刺的猬
有刺的猬 2021-01-13 02:59

Ok so I have a current workbook (Original Workbook) with several Sheets. I would like to open an existing workbook (Data Workbook) and copy all of the contents in Sheet 1 of

相关标签:
1条回答
  • 2021-01-13 03:16

    Does this do what you want?

    Sub ImportData()
    
    Dim wb1 As Workbook
    Dim wb2 As Workbook
    Dim Sheet As Worksheet
    Dim PasteStart As Range
    
    Set wb1 = ActiveWorkbook
    Set PasteStart = [RRimport!A1]
    
    FileToOpen = Application.GetOpenFilename _
    (Title:="Please choose a Report to Parse", _
    FileFilter:="Report Files *.xls (*.xls),")
    
    If FileToOpen = False Then
        MsgBox "No File Specified.", vbExclamation, "ERROR"
        Exit Sub
    Else
        Set wb2 = Workbooks.Open(Filename:=FileToOpen)
    
        For Each Sheet In wb2.Sheets
            With Sheet.UsedRange
                .Copy PasteStart
                Set PasteStart = PasteStart.Offset(.Rows.Count)
            End With
        Next Sheet
    
    End If
    
        wb2.Close
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题