title: VBA - Activate opened workbook
body: <p>I want to read a workbook and copy some cells in another workbook.
  The aim of the code is to copy the cells from the different sheets from one file to the other.</p>
  
  <p>For this propose, I created this code:</p>
  
  <pre><code>Sub processCopy(file)
  
  'Abrir documento
  Workbooks.Open Filename:=file, UpdateLinks:=0
  
  
  cantn = ThisWorkbook.Sheets.Count
  cantv = Sheets.Count - 5
  cantn = cantn - 4
  
  'Recorrer los libros del documento abierto
  For i = 1 To (Sheets.Count - 5)
  
      'Obtener nombre del libro seleccionado
      nombre = Sheets(i + 2).Name
      'Filtrar los libros no necesarios
      If nombre &lt;&gt; "Instructions" And nombre &lt;&gt; "Executive Summary" And nombre &lt;&gt; "Process Update" And nombre &lt;&gt; "Template" And nombre &lt;&gt; "Notes" Then
  
          If cantv &gt;= cantn Then
           ThisWorkbook.Sheets(3).copy after:=ThisWorkbook.Sheets(cantn + 2)
           cantn = cantn + 1
           ThisWorkbook.Sheets(cantn + 2).Name = nombre
          ElseIf nombre &lt;&gt; ThisWorkbook.Sheets(cantn + 2).Name Then
           ThisWorkbook.Sheets(cantn + 2).Name = nombre
          End If
  
          Workbooks.Open Filename:=file, UpdateLinks:=0
  
          ActiveWorkbook.Worksheets(nombre).Activate
  
          ActiveWorkbook.Sheets(nombre).Range("C4:O23").Select
          Selection.copy
          ThisWorkbook.Sheets(nombre).Range("C4:O23").PasteSpecial
  </code></pre>
  
  <p>After finishing the process in the first sheet, I compare if in the new file there is any other sheet to start with the process. If not (always) I create a new sheet to start with the process of copying and pasting, but the functions ThisWorkbook and ActiveWorkbook are working on the same sheet (copying and pasting from the same Workbook) and not from one file to the other.</p>
  
  <p>That is why, I open the first workbook, but when the process of copying and pasting finishes, this message appears:</p>
  
  <p><a href="http://i.stack.imgur.com/cjlY2.png" rel="nofollow">Error image</a></p>
  
  <p>What can i do to solve it this issue?</p>
  
  <p>Thanks for all</p>