title: Copying and pasting data using VBA code
body: <p>I have a button on a spreadsheet that, when pressed, should allow the user to open a file, then copy columns A-G of the spreadsheet "Data", then paste the data from those columns on the current sheet.  </p>
  
  <p>I have a logic error in the code; it runs, but it pastes the selection in the wrong place.  </p>
  
  <p>I am having trouble referencing the two workbooks.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Sub Button1_Click()
      Dim excel As excel.Application
      Dim wb As excel.Workbook
      Dim sht As excel.Worksheet
      Dim f As Object
  
      Set f = Application.FileDialog(3)
      f.AllowMultiSelect = False
      f.Show
  
      Set excel = CreateObject("excel.Application")
      Set wb = excel.Workbooks.Open(f.SelectedItems(1))
      Set sht = wb.Worksheets("Data")
  
      sht.Activate
      sht.Columns("A:G").Select
      Selection.Copy
      Range("A1").Select
      ActiveSheet.Paste
  
      wb.Close
  End Sub
  </code></pre>