Hi Every One,

I'm just trying to write a VBscript to edit an Excel file. Just want t
select a range of cells *using column and row numbers*. Here is m
sample code :

Dim objUser, strExcelPath, objExcel, objSheet, k, objGroup

strExcelPath = "C:\UserGroup.xls"

Dim objXL

Set objExcel = WScript.CreateObject("Excel.Application")

objExcel.Workbooks.Add
objExcel.ActiveWorkbook.Worksheets(2).Select
objExcel.ActiveWindow.SelectedSheets.Delete
objExcel.ActiveWorkbook.Worksheets(2).Select
objExcel.ActiveWindow.SelectedSheets.Delete

Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

objSheet.Cells(1, 1).Value = "User Common Name"
objSheet.Cells(2, 1).Value = "sAMAccountName"
objSheet.Cells(3, 1).Value = "Display Name"
objSheet.Cells(4, 1).Value = "Distinguished Name"
objSheet.Cells(5, 1).Value = "Groups"

objExcel.ActiveWorkbook.SaveAs strExcelPath

objSheet.Range(cells(1,1),cells(2,3)).Select *<-- this doesn't work*
objExcel.ActiveWorkbook.Close

objExcel.Application.Quit

Set objUser = Nothing
Set objGroup = Nothing
Set objSheet = Nothing
Set objExcel = Nothing

Can anyone help me, pleaaaase

Cheers,

The K


-
The K
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Re: Select a Cell Range in Excel using numbers by Richard

Richard
Thu Feb 16 23:58:09 CST 2006

Hi,

Try something similar to:

objSheet.Range(A1:B3).Select

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"The Ki" <The.Ki.23cm9n@mail.codecomments.com> wrote in message
news:The.Ki.23cm9n@mail.codecomments.com...
>
> Hi Every One,
>
> I'm just trying to write a VBscript to edit an Excel file. Just want to
> select a range of cells *using column and row numbers*. Here is my
> sample code :
>
> Dim objUser, strExcelPath, objExcel, objSheet, k, objGroup
>
> strExcelPath = "C:\UserGroup.xls"
>
> Dim objXL
>
> Set objExcel = WScript.CreateObject("Excel.Application")
>
> objExcel.Workbooks.Add
> objExcel.ActiveWorkbook.Worksheets(2).Select
> objExcel.ActiveWindow.SelectedSheets.Delete
> objExcel.ActiveWorkbook.Worksheets(2).Select
> objExcel.ActiveWindow.SelectedSheets.Delete
>
> Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
>
> objSheet.Cells(1, 1).Value = "User Common Name"
> objSheet.Cells(2, 1).Value = "sAMAccountName"
> objSheet.Cells(3, 1).Value = "Display Name"
> objSheet.Cells(4, 1).Value = "Distinguished Name"
> objSheet.Cells(5, 1).Value = "Groups"
>
> objExcel.ActiveWorkbook.SaveAs strExcelPath
>
> objSheet.Range(cells(1,1),cells(2,3)).Select *<-- this doesn't work*
> objExcel.ActiveWorkbook.Close
>
> objExcel.Application.Quit
>
> Set objUser = Nothing
> Set objGroup = Nothing
> Set objSheet = Nothing
> Set objExcel = Nothing
>
> Can anyone help me, pleaaaase
>
> Cheers,
>
> The Ki
>
>
>
> --
> The Ki
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>



Re: Select a Cell Range in Excel using numbers by Michael

Michael
Sat Feb 18 01:18:35 CST 2006

On Thu, 16 Feb 2006 08:22:03 -0600, The Ki wrote in
microsoft.public.scripting.vbscript:

>Hi Every One,
>
>I'm just trying to write a VBscript to edit an Excel file. Just want to
>select a range of cells *using column and row numbers*. Here is my
>sample code :
[snip]
>objSheet.Range(cells(1,1),cells(2,3)).Select *<-- this doesn't work*
[snip]

Try:
With objSheet
.Range(.Cells(1, 1), .Cells(2, 3)).Select
End With

Generally speaking, the Select method is inefficient and hardly ever
necessary. Instead of:
>objExcel.ActiveWorkbook.Worksheets(2).Select
>objExcel.ActiveWindow.SelectedSheets.Delete
>objExcel.ActiveWorkbook.Worksheets(2).Select
>objExcel.ActiveWindow.SelectedSheets.Delete

you could use:

With objExcel
.DisplayAlerts = False
With .ActiveWorkbook
For n = .Worksheets.Count To 2 Step -1
.Worksheets(n).Delete
Next n
End With
.DisplayAlerts = True
End With

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"