View Full Version : Help using VbScript to define Excel range
06-30-2005, 07:04 PM
Does anyone know how to define a range in Excel using vbScript?
ANY help with this is MOST appreciated!
06-30-2005, 08:13 PM
If you mean a selection of cells in a similar row or column by "range", you would have to create an Excel object with VBScript and set it up appropriately. The bold code is how you would select a range, the rest is the creation of an Excel object in VBScript if you hadn't already done so:
Set objXL = WScript.CreateObject("Excel.Application")
objXL.Visible = TRUE
objXL.Columns(1).ColumnWidth = 20
objXL.Columns(2).ColumnWidth = 30
objXL.Columns(3).ColumnWidth = 40
objXL.Cells(1, 1).Value = "Column 1"
objXL.Cells(1, 2).Value = "Column 2"
objXL.Cells(1, 3).Value = "Column 3"
objXL.Range("A1:C1").Select Hope this is what your looking for
07-01-2005, 07:23 PM
You are probably correct, but I am having problems getting it to work with my code.
That gets me an error message saying that it could not find the range.
I am trying to place the contents of the range into a recordset so I can post the values to an ASP page. If I name the range physically in Excel, the code works, but I cannot do that in all of the spreadsheets that folks will choose to display (preview) before they print.
Here is the offending code:
Dim filePath, oExcel,objrange,oRangeName
filePath = "K:\TrainingBudget.xls"
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = TRUE
oRangeName = oExcel.Range("A1:C1").Select
objrange = oRangeName
strCmd = "SELECT * from objrange"
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.Open strCmd, oConn
Thanks for the help. I really appreciate it.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.