title: Using excels named range in a sql string in VBScript
body: <p>I have searched on here and google but I still cannot solve my issue. I am trying to use an excel's named range equivalently in my <code>.vbs</code> file. The below works in VBA in excel but I cannot get it to work in a <code>*.vbs</code> file.</p>
  
  <pre><code>ThisWorkbook.Sheets(1).Range("A1:B" &amp; Range("B" &amp; Rows.Count).End(xlUp).Row).Name = "DATA"
  strSql = "SELECT * FROM DATA"
  </code></pre>
  
  <p>So, I have tried different variations of referencing to my named range <code>DATA</code> with no luck.<br>
  This is what I have now:</p>
  
  <pre><code>Set rng = ws.Range("A1:B2")
  rng = "DATA"    
  strSql = "SELECT * FROM DATA"
  </code></pre>
  
  <p>Some different variations involved: taking parameter ByVal, using rng instead of DATA (string type), <code>SELECT * FROM " &amp; rng, etc..</code></p>
  
  <p>The error msg when running:</p>
  
  <blockquote>
    <p>Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft
    Corporation. All rights reserved.</p>
    
    <p>C:\Users\admin\Desktop\UpdateSourceTbl.vbs(119, 5) Microsoft
    JET Databas e Engine: The Microsoft Jet database engine could not find
    the object 'DATA'.  M ake sure the object exists and that you spell
    its name and the path name correctly.</p>
  </blockquote>
  
  <p>Any help greatly appreciated!</p>
  
  <p><strong>TEMPORARY SOLUTION:</strong>
  I used 2 parameters with row numbers, may not be the best solution - but it works! and i cant see nothing wrong with it to be fair</p>
  
  <pre><code>Call createAndInsertRecordSet(wb.FullName, ws.Name, i+1, j-1)
  Sub CreateAndInsertRecordSet(ByVal fullname, ByVal wsName, ByVal stRow, byVal enRow )
  strSql = "SELECT * FROM [" &amp; wsName &amp; "$B" &amp; stRow &amp; ":AX" &amp; enRow &amp; "]"
  </code></pre>