Hallo Forum,
beim Excel-Export erhalte ich die folgende Fehlermeldung:
Microsoft Office Excel: Die AutoFilter-Eigenschaft des Range-Objektes kann nicht festgelegt werden.
Trotzdem wird brav die Filterfunktion im Excel-Sheet gebracht.
Der Code-Abschnitt endet mit:
xlApp.Application.Selection.Autofilter = True
Kann mir jemand sagen, wie die Range-Angabe heissen muss?
Alexis
Hier der betreffende Abschnitt:
'Erste Reihe Spaltenbeschriftung
xlApp.application.Rows("1:1").Select
With xlApp.application.Selection
.Font.bold = True
.Font.ColorIndex = 0
.Font.Name = "Arial"
.Font.Size = 10
.Interior.ColorIndex = 0
End With
' ---------------------------------------------------------------------------------
'Fenster fixieren
xlApp.application.Rows("2:2").Select
xlApp.application.ActiveWindow.FreezePanes = True
'Aussehen der Spalten und Kopfzeile
xlApp.cells.select
xlApp.selection.Columns.AutoFit
xlApp.application.rows("1:1").Select
xlApp.ActiveSheet.PageSetup.centerheader = "&""Arial Black,Fett"" Database: Plant System Inventory" + " Export created on: " + Format(Now,"dd/MM/yyyy HH:MM")
xlApp.ActiveSheet.PageSetup.PrintTitleRows = "$1:$1"
xlApp.ActiveSheet.PageSetup.PrintGridlines = True
xlApp.ActiveSheet.PageSetup.Orientation = 2
xlApp.Application.DisplayAlerts = False
xlApp.Application.EnableEvents = False
xlApp.Cells.Replace "[" , ""
xlApp.Application.EnableEvents = True
xlApp.Application.DisplayAlerts = True
xlApp.Application.DisplayAlerts = False
xlApp.Application.EnableEvents = False
xlApp.Cells.Replace "]" , ""
xlApp.Application.EnableEvents = True
xlApp.Application.DisplayAlerts = True
xlApp.Application.DisplayAlerts = False
xlApp.Application.EnableEvents = False
xlApp.Cells.Replace "(" , ""
xlApp.Application.EnableEvents = True
xlApp.Application.DisplayAlerts = True
xlApp.Application.DisplayAlerts = False
xlApp.Application.EnableEvents = False
xlApp.Cells.Replace ")" , ""
xlApp.Application.EnableEvents = True
xlApp.Application.DisplayAlerts = True
xlApp.Application.DisplayAlerts = False
xlApp.Application.EnableEvents = False
xlApp.Cells.Replace "<" , ""
xlApp.Application.EnableEvents = True
xlApp.Application.DisplayAlerts = True
xlApp.Application.DisplayAlerts = False
xlApp.Application.EnableEvents = False
xlApp.Cells.Replace ">" , ""
xlApp.Application.EnableEvents = True
xlApp.Application.DisplayAlerts = True
xlApp.Application.DisplayAlerts = False
xlApp.Application.EnableEvents = False
xlApp.Cells.Replace "'" , ""
xlApp.Application.EnableEvents = True
xlApp.Application.DisplayAlerts = True
xlApp.Application.ScreenUpdating = True
xlApp.Application.Selection.Autofilter = True
Alexis
Versuch's mal so:
xlApp.Application.Selection.Autofilter
Die AutoFilter-Eigenschaft ist nämlich schreibgeschützt.
Was mir noch aufgefallen ist, sind die vielen EnableEvents- und DisplayAlerts-Anweisungen. Meines Erachtens kannst du dir die sparen.
...
xlApp.Application.DisplayAlerts = False
xlApp.Application.EnableEvents = False
xlApp.Cells.Replace "[" , ""
xlApp.Cells.Replace "]" , ""
xlApp.Cells.Replace "(" , ""
xlApp.Cells.Replace ")" , ""
xlApp.Cells.Replace "<" , ""
xlApp.Cells.Replace ">" , ""
xlApp.Cells.Replace "'" , ""
xlApp.Application.EnableEvents = True
xlApp.Application.DisplayAlerts = True
xlApp.Application.ScreenUpdating = True
...
Axel