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 .vbs
file. The below works in VBA in excel but I cannot get it to work in a *.vbs
file.
ThisWorkbook.Sheets(1).Range("A1:B" & Range("B" & Rows.Count).End(xlUp).Row).Name = "DATA"
strSql = "SELECT * FROM DATA"
So, I have tried different variations of referencing to my named range DATA
with no luck.
This is what I have now:
Set rng = ws.Range("A1:B2")
rng = "DATA"
strSql = "SELECT * FROM DATA"
Some different variations involved: taking parameter ByVal, using rng instead of DATA (string type), SELECT * FROM " & rng, etc..
The error msg when running:
Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.
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.
Any help greatly appreciated!
TEMPORARY SOLUTION: 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
Call createAndInsertRecordSet(wb.FullName, ws.Name, i+1, j-1)
Sub CreateAndInsertRecordSet(ByVal fullname, ByVal wsName, ByVal stRow, byVal enRow )
strSql = "SELECT * FROM [" & wsName & "$B" & stRow & ":AX" & enRow & "]"
xlUp
is not defined outside of Excel. You need to replace it with its actual value (which you can find using the object browser in excel (F2 in the VB Editor). It would help to update your question with the complete VBscript you're using.