Solved

MS access vba turn of filter in Excel worksheet

Posted on 2014-02-27
5
1,270 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
[X]
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
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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