自动过滤一个受保护的Excel表单从访问打开

我正在从Excel中移动一些代码访问。 在Excel中有一个打开另一个Excel文档并应用自动筛选器的button。

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

这是从Excel中的代码,它用于正常工作,但现在也抛出一个错误,因为工作表受到保护。

使用一些代码,我从这个线程自动筛选Excel与VBA

我想出了代码,应该在访问工作,但没有

我到目前为止是

 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 

我得到.AutoFilter字段错误:= 3,Critera1:= 110,操作员:= 7我不能只是select一个范围自动filter,因为工作表受保护,我没有写权限。 在工作表上已经有自动filter了,我只需要设置一个值。

有没有人知道这个在access或excel中的解决scheme,但最好是两者?

谢谢

我相信一个AutoFilter需要应用到一个范围。 您的“With”语句parsing为工作表,而不是范围。

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

除非有权访问工作表的人员使用以下链接中的信息更改保护,否则不能这样做。

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

我希望这有帮助。