Filtering PivotTable Error HRESULT: 0x80070057 (E_INVALIDARG))

bebekonene1

New Member
I've been working on this object for a week now and still cant get it right. All lines are working just fine except for the last line where it should filter the pivot field "Month" into the current month and previous months. I'm trying to have an output of less than or equal to the current month. Here is my code.

Dim excel as Object

Dim ws as Object = GetWorksheet(handle,workbookname,worksheetname)

excel = ws.Application
excel.ActiveSheet.PivotTables(PivotName).PivotCache.Refresh
excel.ActiveSheet.PivotTables(PivotName).PivotFields(PivotField).ClearAllFilters
excel.ActiveSheet.PivotTables(PivotName).PivotFields(PivotField).PivotFilters.Add(Type:=12,Value1:=(value))

tried having the last line as a comment and the whole thing worked so I really assume the last line is the problem.
the last line seems to be the only problem as it gives me an error of HRESULT: 0x80070057 (E_INVALIDARG))
 
Top