Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default vbscript and Excel

Hi
I need to work with an Excel file using vbscript.

Here is a code snippet:
Set XL = CreateObject("Excel.Application")
XL.Application.Workbooks.Open "c:\temp\Myfile.xls"
XL.Visible = True

'rename sheet etc
XL.ActiveSheet.Name = "PayrollInfo"
XL.Cells.UnMerge

'Add new column headings.. Current data in cols a-e
XL.Range("F1:I1") = Array("TrxDate", "Co", "LineNum", "Acct")

'get the last row of data


With XL
Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(xlUp).Row)

This line fails with error 1004 - Application or object defined error


What am I doing wrong? Thanks in advance for your advice.

REgards
Habib

--
www.DynExtra.com
A resource for the Microsoft Dynamics Community
Featuring FAQs, File Exchange and more
Current member count: 40
--------------------------------------------
Share your knowledge. Add your favorite questions and answers
Help add questions to this site! We want Your input.
--------------------------------------------


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default vbscript and Excel

Change...
.End(xlUp).Row)
To...

.End(.xlUp).Row) ' dot added
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"HSalim[MVP]"
wrote in message
Hi
I need to work with an Excel file using vbscript.

Here is a code snippet:
Set XL = CreateObject("Excel.Application")
XL.Application.Workbooks.Open "c:\temp\Myfile.xls"
XL.Visible = True
'rename sheet etc
XL.ActiveSheet.Name = "PayrollInfo"
XL.Cells.UnMerge
'Add new column headings.. Current data in cols a-e
XL.Range("F1:I1") = Array("TrxDate", "Co", "LineNum", "Acct")
'get the last row of data

With XL
Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(xlUp).Row)

This line fails with error 1004 - Application or object defined error


What am I doing wrong? Thanks in advance for your advice.

REgards
Habib

--
www.DynExtra.com
A resource for the Microsoft Dynamics Community
Featuring FAQs, File Exchange and more
Current member count: 40
--------------------------------------------
Share your knowledge. Add your favorite questions and answers
Help add questions to this site! We want Your input.
--------------------------------------------


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default vbscript and Excel

I didn't run your code but try:

With XL.ActiveSheet

--
Jim
"HSalim[MVP]" wrote in message
...
| Hi
| I need to work with an Excel file using vbscript.
|
| Here is a code snippet:
| Set XL = CreateObject("Excel.Application")
| XL.Application.Workbooks.Open "c:\temp\Myfile.xls"
| XL.Visible = True
|
| 'rename sheet etc
| XL.ActiveSheet.Name = "PayrollInfo"
| XL.Cells.UnMerge
|
| 'Add new column headings.. Current data in cols a-e
| XL.Range("F1:I1") = Array("TrxDate", "Co", "LineNum", "Acct")
|
| 'get the last row of data
|
|
| With XL
| Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(xlUp).Row)
|
| This line fails with error 1004 - Application or object defined error
|
|
| What am I doing wrong? Thanks in advance for your advice.
|
| REgards
| Habib
|
| --
| www.DynExtra.com
| A resource for the Microsoft Dynamics Community
| Featuring FAQs, File Exchange and more
| Current member count: 40
| --------------------------------------------
| Share your knowledge. Add your favorite questions and answers
| Help add questions to this site! We want Your input.
| --------------------------------------------
|
|


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default vbscript and Excel

If this isn't part of excel's VBA, then your script doesn't know what xlUp is.

I opened excel, went to the VBE, hit ctrl-g to see the immediate window and
typed this:

?xlup

and got this:
-4162

So you could try:

Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(-4162).Row)


"HSalim[MVP]" wrote:

Hi
I need to work with an Excel file using vbscript.

Here is a code snippet:
Set XL = CreateObject("Excel.Application")
XL.Application.Workbooks.Open "c:\temp\Myfile.xls"
XL.Visible = True

'rename sheet etc
XL.ActiveSheet.Name = "PayrollInfo"
XL.Cells.UnMerge

'Add new column headings.. Current data in cols a-e
XL.Range("F1:I1") = Array("TrxDate", "Co", "LineNum", "Acct")

'get the last row of data

With XL
Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(xlUp).Row)

This line fails with error 1004 - Application or object defined error

What am I doing wrong? Thanks in advance for your advice.

REgards
Habib

--
www.DynExtra.com
A resource for the Microsoft Dynamics Community
Featuring FAQs, File Exchange and more
Current member count: 40
--------------------------------------------
Share your knowledge. Add your favorite questions and answers
Help add questions to this site! We want Your input.
--------------------------------------------


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default vbscript and Excel

.xlUp

xlUp is just a constant, Jim.

--
Jim
"Jim Cone" wrote in message
...
| Change...
| .End(xlUp).Row)
| To...
|
| .End(.xlUp).Row) ' dot added
| --
| Jim Cone
| San Francisco, USA
| http://www.realezsites.com/bus/primitivesoftware
|
|
| "HSalim[MVP]"
| wrote in message
| Hi
| I need to work with an Excel file using vbscript.
|
| Here is a code snippet:
| Set XL = CreateObject("Excel.Application")
| XL.Application.Workbooks.Open "c:\temp\Myfile.xls"
| XL.Visible = True
| 'rename sheet etc
| XL.ActiveSheet.Name = "PayrollInfo"
| XL.Cells.UnMerge
| 'Add new column headings.. Current data in cols a-e
| XL.Range("F1:I1") = Array("TrxDate", "Co", "LineNum", "Acct")
| 'get the last row of data
|
| With XL
| Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(xlUp).Row)
|
| This line fails with error 1004 - Application or object defined error
|
|
| What am I doing wrong? Thanks in advance for your advice.
|
| REgards
| Habib
|
| --
| www.DynExtra.com
| A resource for the Microsoft Dynamics Community
| Featuring FAQs, File Exchange and more
| Current member count: 40
| --------------------------------------------
| Share your knowledge. Add your favorite questions and answers
| Help add questions to this site! We want Your input.
| --------------------------------------------
|
|




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default vbscript and Excel


But the application the code is being run from doesn't know that.
--
Jim Cone

"Jim Rech"
wrote in message
.xlUp

xlUp is just a constant, Jim.
--
Jim

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default vbscript and Excel


Perfect! that did it. Thank you.
Now, why didn't I think of that?
HS


--
www.DynExtra.com
A resource for the Microsoft Dynamics Community
Featuring FAQs, File Exchange and more
Current member count: 40
--------------------------------------------
Share your knowledge. Add your favorite questions and answers
Help add questions to this site! We want Your input.
--------------------------------------------
"Dave Peterson" wrote in message
...
If this isn't part of excel's VBA, then your script doesn't know what xlUp
is.

I opened excel, went to the VBE, hit ctrl-g to see the immediate window
and
typed this:

?xlup

and got this:
-4162

So you could try:

Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(-4162).Row)


"HSalim[MVP]" wrote:

Hi
I need to work with an Excel file using vbscript.

Here is a code snippet:
Set XL = CreateObject("Excel.Application")
XL.Application.Workbooks.Open "c:\temp\Myfile.xls"
XL.Visible = True

'rename sheet etc
XL.ActiveSheet.Name = "PayrollInfo"
XL.Cells.UnMerge

'Add new column headings.. Current data in cols a-e
XL.Range("F1:I1") = Array("TrxDate", "Co", "LineNum", "Acct")

'get the last row of data

With XL
Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(xlUp).Row)

This line fails with error 1004 - Application or object defined error

What am I doing wrong? Thanks in advance for your advice.

REgards
Habib

--
www.DynExtra.com
A resource for the Microsoft Dynamics Community
Featuring FAQs, File Exchange and more
Current member count: 40
--------------------------------------------
Share your knowledge. Add your favorite questions and answers
Help add questions to this site! We want Your input.
--------------------------------------------


--

Dave Peterson



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default vbscript and Excel

With XL
Set rng = .Range("A1:F" & .Cells(.Rows.Count, "A").End(-4162).Row)
End With

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"HSalim[MVP]" wrote in message
...
Hi
I need to work with an Excel file using vbscript.

Here is a code snippet:
Set XL = CreateObject("Excel.Application")
XL.Application.Workbooks.Open "c:\temp\Myfile.xls"
XL.Visible = True

'rename sheet etc
XL.ActiveSheet.Name = "PayrollInfo"
XL.Cells.UnMerge

'Add new column headings.. Current data in cols a-e
XL.Range("F1:I1") = Array("TrxDate", "Co", "LineNum", "Acct")

'get the last row of data


With XL
Set rng =.Range("A1:F" & .Cells(.Rows.Count, "A").End(xlUp).Row)

This line fails with error 1004 - Application or object defined error


What am I doing wrong? Thanks in advance for your advice.

REgards
Habib

--
www.DynExtra.com
A resource for the Microsoft Dynamics Community
Featuring FAQs, File Exchange and more
Current member count: 40
--------------------------------------------
Share your knowledge. Add your favorite questions and answers
Help add questions to this site! We want Your input.
--------------------------------------------




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default vbscript and Excel


My apologies, my suggestion doesn't even come close to working.
Jim Cone


"Jim Rech" wrote in message ...
.xlUp


xlUp is just a constant, Jim.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run VBScript from Excel Amy M Excel Discussion (Misc queries) 4 September 19th 08 09:07 PM
Vbscript Excel question Catherine Jackson Excel Programming 0 July 30th 06 11:31 PM
Excel & VBScript Bill Ebbing Excel Programming 7 September 8th 05 06:27 PM
Using excel through vbscript ashtom1 Excel Programming 6 July 6th 05 02:55 PM
VBScript code behind Excel jjjjj Excel Programming 2 November 23rd 04 10:36 PM


All times are GMT +1. The time now is 02:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"