title: How to open and activate another workbook in VBA?
body: <p>I'm creating a macro where I will need to run it in 1 file (called "Masterfile"), it will open and execute the macro on another file ("SurveyReport") and then give me a message box saying "done!".</p>
  
  <p>The code I have to execute on the SurveyReport file works fine when I open that file manually and execute it. The code I need to open SurveyReport from MasterFile is also working it seems, I ran the below with no issues:</p>
  
  <pre><code>    Sub PivotTable()
      '
      ' PivotTable Macro
  
      Dim MasterFile As String
  
      MasterFile = ActiveWorkbook.Name
  
      Dim SurveyReport As String
  
      SurveyReport = Application.GetOpenFilename("Excel files (*.xlsx), *xlsx", 1, "Please select the Survey Create Report file", , False)
  
      Workbooks.Open (SurveyReport)
  
  
      End Sub
  </code></pre>
  
  <p>But, when I try to activate the SurveyReport file so I can begin executing the macro in it, I get a "Subscript out of range" error. I've tried using the following code after the above block and before the code to execute in the SurveyReport file:</p>
  
  <pre><code>    Windows(SurveyReport).Activate
  </code></pre>
  
  <p>This didn't work, not did:</p>
  
  <pre><code>    ThisWorkbook.Activate
  </code></pre>
  
  <p>...which only had the effect of activating the MasterFile.</p>
  
  <p>SurveyReport file is a .xlsx file. I tried saving it as a .xls file and amending the code, but no joy.
  I also tried passing it the file name directly (i.e. Windows("filename.xlsx").Activate), same issue.</p>