Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

MS access vba turn of filter in Excel worksheet

Posted on 2014-02-27
5
1,213 Views
Last Modified: 2014-02-27
From Ms access using VBA turn off filter in MS Excel sheet.  Some time user leave the filter turn on in Excel sheet. This cause the import to fail.
Ms Acess 2010
Excel 2010

I need to turn the filter off in the Excel sheet using VBA from Ms Access.

Thank you
0
Comment
Question by:newholyman
  • 3
  • 2
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39892211
How are you currently importing your data?  If you are using Excel Automation try setting the autofilter mode of your worksheet object:


xlWS.AutoFilterMode = False


if you are not currently using automation, it is done similar to this:


Dim xlApp as Excel.Application
Dim xlWB  Excel.Workbook
Dim xlWS as Excel.Worksheet

Set xlApp = New Excel.Application
Set xlWB = xlApp.Workbooks.Open("C:\Yourfilename.xls")
Set xlSH = xlWB.Sheets("YourWorkSheet")

if xlWS.AutoFilterMode = True then xlWS.AutoFilterMode = False

 ' etc

' clear up objects

xlwb,close
xlapp.quit
set xlwb = nothing
set xlapp = nothing
setxlws = nothing

Open in new window

0
 

Author Comment

by:newholyman
ID: 39892493
received error message object does not support this object or method

Dim xlObj As Object, Sheet As Object
Dim xlFile As String
xlFile = ("file")
Rem xlFile = wrk_copy
    Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.Open xlFile
    xlObj.Visible = True
    Set Sheet = xlObj.ActiveWorkbook.Worksheets("sheetname")
    If xlObj.AutoFilterMode = True Then xlObj.AutoFilterMode = False
  xlObj.ActiveWorkbook.Save
  xlObj.ActiveWorkbook.Close
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39892661
<<If you are using Excel Automation try setting the autofilter mode of your worksheet object >>

Your code is trying to set the autofilter mode of the *application* object (xlObj), which may be the cause of your error.

It should be on the worksheet object (declared as "Sheet" in your code)
0
 

Author Closing Comment

by:newholyman
ID: 39892758
Here the final vba that worked;
Dim xlObj As Object, Sheet As Object
Dim xlFile As String
xlFile = ("file")
Rem xlFile = wrk_copy
    Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.Open xlFile
    xlObj.Visible = True
    Set Sheet = xlObj.ActiveWorkbook.Worksheets("sheetname")
    If Sheet.AutoFilterMode = True Then Sheet.AutoFilterMode = False
  xlObj.ActiveWorkbook.Save

Thank you
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39892818
If the suggestion I posted did the trick (If Sheet.AutoFilterMode = True Then Sheet.AutoFilterMode = False), why did you award a B grade?

EE's grading standards are here:

http://support.experts-exchange.com/customer/portal/articles/481419-what-grade-should-i-award-?b_id=44

A B grade means the solution given lacked some information or required you to do a good amount of extra work to resolve the problem. When closing the question, the asker should explain why a B grade was awarded.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question