从Excel中删除过滤器,从VBA中导入Access数据文件

时间:2015-03-02 11:24:29

标签: excel-vba import access-vba vba excel

我从Access导入Excel数据(表)文件,但我无法删除过滤器。我收到1004错误(删除范围失败)。我也不能手工删除它。

Sub Openaccessdatafile()

'Niet blad updaten
Application.ScreenUpdating = False

Sheets.Add.Name = "Gegevens alginaten"
  Set sh = ThisWorkbook.Sheets("Gegevens alginaten")
LR = sh.Cells(Rows.Count, "A").End(xlUp).Row
Filename = Application.GetOpenFilename("Excel files (*.xls*), *.xls*")
 MsgBox Filename
If Filename <> False Then
  Workbooks.Open (Filename)
    ActiveSheet.UsedRange.Copy sh.Range("A" & LR)
  ActiveWorkbook.Close
 Sheets("Start").Cells(2, 5).Value = "Ok"
Else
 MsgBox "Geen bestand aangeklikt."
 Application.DisplayAlerts = False
 Sheets("Gegevens alginaten").Delete
 Application.DisplayAlerts = True
End If

'Wel blad updaten
Application.ScreenUpdating = True
Sheets("Start").Select
End Sub

1 个答案:

答案 0 :(得分:0)

显然通过VBA宏按钮使用Access导出它确实更好。我可以删除该行,因为未在导出的文件中添加过滤器。