PC Review


Reply
Thread Tools Rate Thread

AutoFilter method of Range class failed

 
 
kevjlang
Guest
Posts: n/a
 
      9th Apr 2010
Hello,

I'm trying to automate some formatting of an Excel 2007 workbook using
VB.NET in Visual Studio for Applications to run as a Script Task in SqlServer
Integration Services. I have a fairly simple range, and I'm able to do
everything I want with it, except for Autofilter. I've tried various methods
for specifying the range (explicit, A1, UsedRange, Columns, etc.) No matter
what I do, I keep getting an exception with the message of "AutoFilter method
of Range Class failed".

I've declared variables for the application, workbook, worksheet, and range
and currently have the following code:

xlWorkBook=xlApp.Workbooks.Open("my.xlsx")
xlWorkSheet=CType(xlWorkbook.Sheets("Sheet1"), _
Microsoft.Office.Interop.Excel.Worksheet)
xlWorkSheet.Activate()
xlWorkSheet.Unprotect()
xlWorkSheet.Range("A1").Select()
xlWorkSheet.Range("A1").Activate() ' didn't change anything after adding
xlWorkSheet.EnableAutoFilter = True ' didn't change anything after adding
xlWorkSheet.Range("A1").AutoFilter()
xlWorkBook.Save()
xlWorkBook.Close()

I've been banging my head for a couple of days trying to find a solution to
this. The onlything that I've found would seem t translate to:

xlWorkSheet.Application.Selection.Autofilter(), however that doesn't seem to
be supported by the Office 12 PIAs.

If anyone has any ideas, I'm open to trying anything.

Thank you,

kevjlang
 
Reply With Quote
 
 
 
 
kevjlang
Guest
Posts: n/a
 
      15th Apr 2010
Well, I altered the code to use Option Strict Off and changed my call to
AutoFilter to use an Object as the Range Object's base class, and it works
now. However, I'd like to know why early binding isn't working. Does anyone
have any ideas as to what might be wrong? Do I have some version mismatches
in my PIAs or between the PIAs and the Excel or Window DLLs?

Any advice will be greatly appreciated.

Thank you,

kevjlang

"kevjlang" wrote:

> Hello,
>
> I'm trying to automate some formatting of an Excel 2007 workbook using
> VB.NET in Visual Studio for Applications to run as a Script Task in SqlServer
> Integration Services. I have a fairly simple range, and I'm able to do
> everything I want with it, except for Autofilter. I've tried various methods
> for specifying the range (explicit, A1, UsedRange, Columns, etc.) No matter
> what I do, I keep getting an exception with the message of "AutoFilter method
> of Range Class failed".
>
> I've declared variables for the application, workbook, worksheet, and range
> and currently have the following code:
>
> xlWorkBook=xlApp.Workbooks.Open("my.xlsx")
> xlWorkSheet=CType(xlWorkbook.Sheets("Sheet1"), _
> Microsoft.Office.Interop.Excel.Worksheet)
> xlWorkSheet.Activate()
> xlWorkSheet.Unprotect()
> xlWorkSheet.Range("A1").Select()
> xlWorkSheet.Range("A1").Activate() ' didn't change anything after adding
> xlWorkSheet.EnableAutoFilter = True ' didn't change anything after adding
> xlWorkSheet.Range("A1").AutoFilter()
> xlWorkBook.Save()
> xlWorkBook.Close()
>
> I've been banging my head for a couple of days trying to find a solution to
> this. The onlything that I've found would seem t translate to:
>
> xlWorkSheet.Application.Selection.Autofilter(), however that doesn't seem to
> be supported by the Office 12 PIAs.
>
> If anyone has any ideas, I'm open to trying anything.
>
> Thank you,
>
> kevjlang

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofilter method of range class failed Scott Microsoft Excel Programming 2 8th Sep 2009 12:49 PM
AutoFilter method of Range class failed =?Utf-8?B?bWFib2xp?= Microsoft Excel Programming 2 17th Nov 2006 02:19 PM
AutoFilter method of Range class failed =?Utf-8?B?YmxvcHJlc3RlMzE4MA==?= Microsoft Excel Programming 1 17th Jan 2006 10:40 PM
Autofilter method of range class failed Terry K Microsoft Excel Programming 5 18th Oct 2005 03:09 AM
AutoFilter method of Range Class Failed Randy Reese Microsoft Excel Programming 2 3rd Apr 2004 04:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:18 AM.