[SOLVED] Problems with invoke code and passing string arguments

Hello all,

My objective is to manipulate a pivot table in one excel using invoke code. One of my issues relies in filtering one of the fields. For this i’m using the following :

Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim p_ws As Microsoft.Office.Interop.Excel.Worksheet

excel = New Microsoft.Office.Interop.Excel.ApplicationClass ‘create the instance of excel workbook’

wb = excel.Workbooks.Open(reportPath) ‘Open the excel the file’
excel.Visible=True

ws=CType(wb.Sheets(strSheetPivotTable),Microsoft.Office.Interop.Excel.Worksheet) ‘select a sheet and activates’
ws.Activate

'Select pivot table ’

Dim oPivotTable As Microsoft.Office.Interop.Excel.PivotTable=Nothing

oPivotTable = CType(ws.PivotTables(“PivotTable1”),Microsoft.Office.Interop.Excel.PivotTable) ’ Select Pivot Table
oPivotTable.ClearAllFilters

‘Creation of pivot Fields’

Dim oPivotField As Microsoft.Office.Interop.Excel.PivotField=Nothing

oPivotField=CType(oPivotTable.PivotFields(“SP Cleaned”),Microsoft.Office.Interop.Excel.PivotField)‘Put the column “Cost Center” on the square “Column” of the Pivot’
oPivotField.Orientation=Microsoft.Office.Interop.Excel.XlPivotFieldOrientation.xlPageField

oPivotField.CurrentPage = StrSalesProduct

The StrSalesProduct is one argument with direction “in” and with string type.

I’m able to do this if StrSalesProduct was a int32 i could make .tostring and it works but for a string I’m allways having this problem :

image

I’m not understanding why this is happening for the string argument. What i’m doing wrong ?

Thanks in advance.

[SOLVED]

Hi @NunesDio,

I’m glad you found the solution to your problem, it would be great if you can share the solution with the community to help someone in future.

Happy Automating!

Regards,
PD

2 Likes