Autofilter a protected excel sheet opened from access

RJ Coulton

Im currently moving some code from excel to access. In excel there is a button that opens another excel document and applies an autofilter.

Dim cell As Long
cell = Sheet2.Cells(9, "i").Value    
Workbooks.Open Filename:= _
        "C:/worksheet1.xls"
      Selection.AutoFilter Field:=3, Criteria1:=cell

This is the code from excel and it used to work fine but now also throws an error because the sheet is protected.

Using some code I got from this thread Autofilter Excel with VBA

I came up with code that should work in access but doesn't

What I have so far is

Dim oApp As Object
Dim wb As Object
Dim ws As Object

Set oApp = CreateObject("Excel.Application")
oApp.Visible = True

'tries to open workbook
On Error Resume Next
'change file path to the correct one
Set wb = oApp.Workbooks.Open(FileName:="C:/worksheet1.xls")
On Error GoTo 0

'if workbook succesfully opened, continue code
If Not wb Is Nothing Then
    'specify worksheet name
    Set ws = wb.Worksheets("BOM")
    With ws
        'apply new filter
        .Cells(3, 3).Select
        .AutoFilter Field:=3, Criteria1:=110, Operator:=7
    End With
End If

Set wb = Nothing
Set oApp = Nothing

Im getting an error on the .AutoFilter Field:=3, Critera1:=110, Operator:=7 I cant just select a range to autofilter because the sheet is protected and I do not have write access. There is already autofilters in place on the sheet I just need to set the value of one.

Does anybody know a solution to this in either access or excel but preferably both?

Thanks

Kevin Francis

I believe an AutoFilter needs to be applied to a Range. Your "With" statement resolves to a worksheet, not a range.

ws.Range(xxxxxx).Autofilter Field:=3, Criteria1:=110, Operator:=7

Unless someone that has access to the worksheet changes the protection using information from the following link, this cannot be done.

http://office.microsoft.com/en-us/excel-help/enable-autofilter-functionality-for-a-protected-worksheet-HA001098270.aspx

I hope this helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Autofilter a protected excel sheet opened from access

From Dev

Remove protected view from Excel sheet opened programmatically in Access

From Dev

Clicking a hyperlink in Excel to set autofilter on a different sheet

From Dev

Excel protected sheet BeforeDoubleClick event

From Dev

Edit open Excel sheet from Access VBA

From Dev

VBA - AutoFilter to append weekend dates from a RawData Sheet to a Weekend Sheet

From Dev

Bring Access Window On Top When Opened From Excel

From Dev

Specifying User Permissions in VBA for Protected Excel Sheet

From Dev

Excel VBA - sheet being protected too quickly

From Dev

excel vba - autofilter from selected range

From Dev

VBA Copy and Paste in another Sheet from AutoFilter outputting one row

From Dev

With Microsoft Excel VBA, can you access one sheet from another?

From Dev

With Microsoft Excel VBA, can you access one sheet from another?

From Dev

Import to Specific Excel Sheet from Access via VBA

From Dev

When a .csv file is opened in excel and saved as an excel sheet .does it have the same properties as that of an original excel sheet?

From Dev

How to enable Cell re-size on protected Excel Sheet

From Dev

How to disable save and protected sheet prompt in excel using VBA

From Dev

Excel: Find out who password protected a individual sheet on book

From Dev

Unable to Reflectively Instantiate a "protected" class of an "opened" package, from another module

From Dev

Excel-VBA : FillDown not working when sheet has an AutoFilter applied & row containing calculations is hidden by filter settings

From Dev

How to transfer criteria from string array to autofilter. VBA Excel

From Dev

excel VBA - return Criteria1 Array from an Autofilter

From Dev

excel vba Assign cell value to variable from Autofilter result

From Dev

excel VBA - return Criteria1 Array from an Autofilter

From Dev

Detect autofilter on Excel Tables

From Dev

Set AutoFilter in Excel with VBA

From Dev

Excel autofilter errors

From Dev

Excel VBA AutoFilter Codes

From Dev

Excel VBA AutoFilter Percentages

Related Related

  1. 1

    Autofilter a protected excel sheet opened from access

  2. 2

    Remove protected view from Excel sheet opened programmatically in Access

  3. 3

    Clicking a hyperlink in Excel to set autofilter on a different sheet

  4. 4

    Excel protected sheet BeforeDoubleClick event

  5. 5

    Edit open Excel sheet from Access VBA

  6. 6

    VBA - AutoFilter to append weekend dates from a RawData Sheet to a Weekend Sheet

  7. 7

    Bring Access Window On Top When Opened From Excel

  8. 8

    Specifying User Permissions in VBA for Protected Excel Sheet

  9. 9

    Excel VBA - sheet being protected too quickly

  10. 10

    excel vba - autofilter from selected range

  11. 11

    VBA Copy and Paste in another Sheet from AutoFilter outputting one row

  12. 12

    With Microsoft Excel VBA, can you access one sheet from another?

  13. 13

    With Microsoft Excel VBA, can you access one sheet from another?

  14. 14

    Import to Specific Excel Sheet from Access via VBA

  15. 15

    When a .csv file is opened in excel and saved as an excel sheet .does it have the same properties as that of an original excel sheet?

  16. 16

    How to enable Cell re-size on protected Excel Sheet

  17. 17

    How to disable save and protected sheet prompt in excel using VBA

  18. 18

    Excel: Find out who password protected a individual sheet on book

  19. 19

    Unable to Reflectively Instantiate a "protected" class of an "opened" package, from another module

  20. 20

    Excel-VBA : FillDown not working when sheet has an AutoFilter applied & row containing calculations is hidden by filter settings

  21. 21

    How to transfer criteria from string array to autofilter. VBA Excel

  22. 22

    excel VBA - return Criteria1 Array from an Autofilter

  23. 23

    excel vba Assign cell value to variable from Autofilter result

  24. 24

    excel VBA - return Criteria1 Array from an Autofilter

  25. 25

    Detect autofilter on Excel Tables

  26. 26

    Set AutoFilter in Excel with VBA

  27. 27

    Excel autofilter errors

  28. 28

    Excel VBA AutoFilter Codes

  29. 29

    Excel VBA AutoFilter Percentages

HotTag

Archive