[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’

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

'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

‘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.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 :


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

Thanks in advance.


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!