Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBScript MS Excel Problem

Hi All,

Just wondering if anyone knows the correct way to pass arguments to the
autofilter method when using VBScript to automate MS Excel. Below, please
find a code snippet that keeps failing.

Code:
Set o_excel = CreateObject("excel.application")
o_excel.visible = True
o_excel.workbooks.open v_file + ".csv"
Set o_wrksht = o_excel.activesheet
o_wrksht.cells(2, 1).autofilter
o_wrksht.cells(2, 10).autofilter 10, "="
The last line returns an error, "Autofilter Method Of Range Class Failed".
Does anyone have any suggestions?


  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default VBScript MS Excel Problem

Hi, David. I've done AutoFilter within Excel VBA a few times, and very
little scripting. Excel VBA Help for the AutoFilter method shows the filter
applied to a range with the column identified in the Field argument. If you
can, step through or Stop this code just after
o_wrksht.cells(2, 1).autofilter

and see if your AutoFilter did indeed come on (the drop-down arrows are
showing). If not, then your next line would error because you can't set the
AutoFilter arguments if the filter isn't on.

If the AutoFilter is on, then just off the top of this shallow fount of
experience, I would say try something like:
o_wrksht.autofilter 10, "="

If that doesn't work, you might try setting an Excel range object and using
the filter on that.

HTH
Ed

"David Layzell" wrote in message
.. .
Hi All,

Just wondering if anyone knows the correct way to pass arguments to the
autofilter method when using VBScript to automate MS Excel. Below, please
find a code snippet that keeps failing.

Code:
Set o_excel = CreateObject("excel.application")
 o_excel.visible = True
 o_excel.workbooks.open v_file + ".csv"
 Set o_wrksht = o_excel.activesheet
 o_wrksht.cells(2, 1).autofilter
 o_wrksht.cells(2, 10).autofilter 10, "="

The last line returns an error, "Autofilter Method Of Range Class Failed".
Does anyone have any suggestions?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBScript MS Excel Problem

Hi Ed,

Thanks for the wonderful response. You're 100x more helpful than Google
today. However, I've discovered the problem. Autofilter is indeed on,
however, when I try to autofilter with that particular cell selected, the
command fails, as there is no data in that column. Turns out the problem
wasn't with this specific command, rather, previous processing errors.
Thanks again for the help!

Dave

"Ed" wrote in message
...
Hi, David. I've done AutoFilter within Excel VBA a few times, and very
little scripting. Excel VBA Help for the AutoFilter method shows the
filter applied to a range with the column identified in the Field
argument. If you can, step through or Stop this code just after
o_wrksht.cells(2, 1).autofilter

and see if your AutoFilter did indeed come on (the drop-down arrows are
showing). If not, then your next line would error because you can't set
the AutoFilter arguments if the filter isn't on.

If the AutoFilter is on, then just off the top of this shallow fount of
experience, I would say try something like:
o_wrksht.autofilter 10, "="

If that doesn't work, you might try setting an Excel range object and
using the filter on that.

HTH
Ed

"David Layzell" wrote in message
.. .
Hi All,

Just wondering if anyone knows the correct way to pass arguments to the
autofilter method when using VBScript to automate MS Excel. Below, please
find a code snippet that keeps failing.

Code:
Set o_excel = CreateObject("excel.application")
 o_excel.visible = True
 o_excel.workbooks.open v_file + ".csv"
 Set o_wrksht = o_excel.activesheet
 o_wrksht.cells(2, 1).autofilter
 o_wrksht.cells(2, 10).autofilter 10, "="

The last line returns an error, "Autofilter Method Of Range Class
Failed". Does anyone have any suggestions?





  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default VBScript MS Excel Problem

Turns out the problem wasn't with this specific command, rather, previous
processing errors.


I hate it when that happens!! 8{

Glad you found the issue. It's always good to see a problem solved.

Ed

"David Layzell" wrote in message
.. .
Hi Ed,

Thanks for the wonderful response. You're 100x more helpful than Google
today. However, I've discovered the problem. Autofilter is indeed on,
however, when I try to autofilter with that particular cell selected, the
command fails, as there is no data in that column. Turns out the problem
wasn't with this specific command, rather, previous processing errors.
Thanks again for the help!

Dave

"Ed" wrote in message
...
Hi, David. I've done AutoFilter within Excel VBA a few times, and very
little scripting. Excel VBA Help for the AutoFilter method shows the
filter applied to a range with the column identified in the Field
argument. If you can, step through or Stop this code just after
o_wrksht.cells(2, 1).autofilter

and see if your AutoFilter did indeed come on (the drop-down arrows are
showing). If not, then your next line would error because you can't set
the AutoFilter arguments if the filter isn't on.

If the AutoFilter is on, then just off the top of this shallow fount of
experience, I would say try something like:
o_wrksht.autofilter 10, "="

If that doesn't work, you might try setting an Excel range object and
using the filter on that.

HTH
Ed

"David Layzell" wrote in message
.. .
Hi All,

Just wondering if anyone knows the correct way to pass arguments to the
autofilter method when using VBScript to automate MS Excel. Below,
please find a code snippet that keeps failing.

Code:
Set o_excel = CreateObject("excel.application")
 o_excel.visible = True
 o_excel.workbooks.open v_file + ".csv"
 Set o_wrksht = o_excel.activesheet
 o_wrksht.cells(2, 1).autofilter
 o_wrksht.cells(2, 10).autofilter 10, "="

The last line returns an error, "Autofilter Method Of Range Class
Failed". Does anyone have any suggestions?







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
Excel sorting in VBScript Gary Foreman Excel Programming 3 February 28th 06 06:56 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
how to kill excel using a vbscript Harald Staff[_4_] Excel Programming 0 July 17th 03 10:02 PM


All times are GMT +1. The time now is 09:45 AM.

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

About Us

"It's about Microsoft Excel"