Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA functions in VBScript

Status
Not open for further replies.

Katto

Technical User
Apr 6, 2005
42
US
Hello,

I have this script and the LastColumn and LastRow lines do not work. Any suggestions?

Thank you

Code:
Set objExcel = CreateObject("Excel.Application")
strExcelPath="C:\TMP\TEST.XLSX"
objExcel.Workbooks.Open strExcelPath
objExcel.Visible = True
Set objSheet = objExcel.ActiveWorkbook.Worksheets(2)
With objExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(2)
LastColumn = objSheet.Cells(1, .Columns.Count).End(xlToRight).Column
LastRow = objSheet.Cells(.Rows.Count, 4).End(xlUp).Row
End With
 
In this context xlToRight and xlUp are 0s. In excel VBE open object browser, check their values and use in the script.

combo
 
Hi,

You cannot use Excel constants like xlToRight.

Google to look up the correct values.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
 
If a reply proved to be the answer, please consider clicking the "Great post!" link.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top