Sample code:
Sub tgr()
'Declare variables
Dim wsDest As Worksheet 'This is the sheet that data will be written to
Dim strFilePath As String 'This is a string variable that will contain the full path to the chosen file
'Use Application.GetOpenFilename to allow user to choose a specific file
strFilePath = Application.GetOpenFilename("Excel Files, *.xls*")
If strFilePath = "False" Then Exit Sub 'User pressed cancel, exit macro
'Assign wsDest to the appropriate sheet
Set wsDest = ActiveWorkbook.ActiveSheet
'Turn off screenupdating so user doesn't see the chosen workbook being opened and operations performed
'This avoids "screen flickering" because executed actions happen very rapidly
'Turning this off also speeds up code run-time because it doesn't have to display what's happening on the screen
Application.ScreenUpdating = False
With Workbooks.Open(strFilePath)
'Do stuff with the workbook here
'For example, this will copy sheet1 cell A1 to the next available row in column A of wsDest:
.Sheets(1).Range("A1").Copy wsDest.Cells(Rows.Count, "A").End(xlUp).Offset(1)
'Close the workbook, don't save changes
.Close False
End With
'Turn screenupdating back on
Application.ScreenUpdating = True
'Object variable cleanup
Set wsDest = Nothing
End Sub
Bookmarks