Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Range.End(xlUp) in Vbscript

1,597 views
Skip to first unread message

Palantir

unread,
Sep 27, 2006, 12:46:02 AM9/27/06
to
I thought I would try to be smart and dump some data into an .xls file via a
vbscript. So I used the code below.

///////////////

Dim objexcel

Set objExcel = createobject("Excel.application")

objexcel.Visible = True

objexcel.Workbooks.open ("C:\kena.xls")
objexcel.Sheets("Data").Range("a65536").End(XlDirection.xlUp).Offset(1,
0).Select 'this is the problem line

objexcel.ActiveCell.Value = "Testing"
objexcel.ActiveCell.offset(1,0)= "Fun"
objexcel.ActiveWorkbook.Save
objexcel.Quit

Everything is fine except the line that tries to find the first free line in
the "a" column of the worksheet. It has a real problem with the End method.
Normally in VBA, you can just say ..End(xlUp), but that doesn't work in
vbscript. So i tried XlDirection.xlUp (the error message was "object required
XlDirection") and also objExcel.XlDirection.xlUp (the error message is
"Object doesn't support this property or method")

If I take out the end method from the line everything works fine, so it
seems like vbscript just can't figure out what I mean when I say, xlUp. Like
I need to refer to a different object or library or something.

Thanks

McKirahan

unread,
Sep 27, 2006, 2:07:28 AM9/27/06
to
"Palantir" <Pala...@discussions.microsoft.com> wrote in message
news:2EC2F870-3831-490B...@microsoft.com...

Are your "xl" prefixed items defined as constants?

Also see:
http://www.xtremevbtalk.com/archive/index.php/t-259299.html


Palantir

unread,
Sep 28, 2006, 6:56:01 AM9/28/06
to
That was the problem ! I didn't realize that XlUp was a constant. So I did a
Const xlup = -4162 (per the VBA object lib) and viola ! its all good.

Thanks.

0 new messages