title: How can I use ActiveWorkbook/Workbooks(name) without getting a Runtime Error 91 in Excel 2013 VBA?
body: <p>While this is not the first time I wrote macros like this, I cant seem to figure out how I get this to work. I have a snipped below that I think <em>should</em> work but doesn't. </p>
  
  <p>My problem is that while at the beginning of my work day the snipped worked exactly <em>once</em>, but afterwards I always get the <strong>Runtime Error '91: object variable or with-block variable not set</strong> error message.</p>
  
  <p>I have two workbooks opened, and I selected cells within the workbook I wanted to work with <em>manually</em> before starting the macro.</p>
  
  <pre><code>Option Explicit
  Sub test()
  
  Dim source, sheet As Worksheet
  Dim sourcename As String
  Dim targetname As String
  Dim test As Workbook
  Workbooks("Test.xlsm").Activate
  test = ActiveWorkbook
  Debug.Print (test.Name)
  
  sourcename = "Tabelle1"
  targetname = "Tabelle2"
  
  Set sheet = ActiveWorkbook.Worksheets(sourcename)
  Set source = ActiveWorkbook.Worksheets(targetname)
  
  Debug.print(sheet.Name)
  Debug.print(source.Name)
  
  End Sub
  </code></pre>
  
  <p>The error occurs in the line containing <code>test = ActiveWorkbook</code></p>
  
  <p><strong>EDIT:</strong> After the initial <code>Set</code>error was fixed, the <em>sheet</em> and <em>source</em> variables are still empty, thus each is causing another error of this type.</p>
  
  <p>What is the problem here and how can I fix it?</p>