title: RunTime Error 91 Object variable or With block variable not set - Use of Public Variables
body: <p>I am currently working on a project that consolidates information from a number of workbooks. While the first version of the application used <code>Select</code> and <code>Activate</code> extensively, from the information I have seen on this site, the use of these methods should be avoided where possible. As such, I am currently re-vamping the code to eliminate these where possible.</p>
  
  <p>The workbook I am using has a reference sheet which is VeryHidden. In order to reference this sheet, I have made a number of public declarations at the start of the first module; one of which is </p>
  
  <pre><code>Public refsheet as Worksheet
  </code></pre>
  
  <p>Please note that this Module may not be used after the workbook has been opened. </p>
  
  <p><strong>QUESTION 1</strong>: Does this cause an issue if I have my public variables defined in this module when not used? If it does cause an issue, where should these public variables be defined?</p>
  
  <p>In the <code>Workbook_Open()</code> event, I have the following:</p>
  
  <pre><code>Private Sub Workbook_Open()
  
  Set refsheet = Sheets("References")
  Set corang = Sheets("Consolidation").Range("L2:AI2")
  
  Application.ScreenUpdating = False
  refsheet.Visible = xlSheetVeryHidden
  Application.ScreenUpdating = True
  
  
  End Sub
  </code></pre>
  
  <p><strong>QUESTION 2</strong>: If I set refsheet in the Workbook_Open() sub, will it be available for use in all other modules given that it has been defined as a public variable? </p>
  
  <p>When I run the code for the first time after using, the first use of refsheet is fine and then anytime refsheet is used after that, I am receiving a Runtime Error 91; Object Variable or With block variable not set.</p>