Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As this doesn't pertain to my other (non) answer, but once again I need to include some code, I'll put it here.</p> <p>In your "variables" module you're <em>declaring</em> variables:</p> <pre><code>dim wb as Workbook </code></pre> <p>Before you can use this variable you must <em>initialise</em> it, i.e. give it a value (any of these examples will work, each are for different scenarios):</p> <pre><code>set wb = ThisWorkbook set wb = ActiveWorkbook set wb = Application.Workbooks(1) </code></pre> <p>If you <em>don't</em> initialise this variable before accessing it, like in this example:</p> <pre><code>dim wb as Workbook debug.print wb.name </code></pre> <p>You'll receive the error: "Run-time error '91': Object variable or With block variable not set"</p> <p>Only object variables require initialisation. Other data types do not. Simply put, non-object data types are as follows. Default values (initialised at declaration) are in brackets:</p> <ul> <li>Integer [0]</li> <li>Long [0]</li> <li>String [""]</li> <li>Double [0]</li> <li>Single [0]</li> <li>Date [0, or December 30, 1899]</li> <li>Byte [0]</li> <li>Boolean [False]</li> <li>Currency [$0]</li> </ul> <p>Everything else is an object and requires some sort of initialisation. An example follows:</p> <pre><code>Option Explicit Dim wb as Workbook Dim app as Excel.Application Dim wrk as Worksheet Set app = Application Set wb = app.workbooks(1) Set wrk = wb.sheets(1) 'If any of the lines preceding this line are skipped, an error will occur. debug.print wrk.name </code></pre> <p>Sorry if you already know this (really, I am, this was a lot to write!) just wanted to make sure we're on the same page after our comment discussion above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload