Need Help! Filtering PivotTable Error HRESULT: 0x80070057 (E_INVALIDARG))

bebekonene1

New Member
sample pivot.jpg - PivotTable
sample pivot2.jpg - object input
sample pivot3.jpg - code

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))
 

Attachments

  • samplepivot3.JPG
    42.2 KB · Views: 6
  • samplepivot2.JPG
    26 KB · Views: 2
  • samplepivot.JPG
    18 KB · Views: 2

LeoLugo

Member
excel.ActiveSheet.PivotTables(PivotName).PivotFields(PivotField).PivotFilters.Add(Type:=12,Value1:=value)
Try this
 
Top