PivotTable_Excel / Copy paste data

Hello fellow member,

My coding background being non existant, I struggle finding code for the following purpose:

Taking the data from a pivot table and copy it into another Excel file.

So far I’m with

Microsoft.Office.Interop.Excel.Application
Dim excel As New Application
Dim sourceWorkbook As Microsoft.Office.Interop.Excel.Workbook = excel.Workbooks.Open(“str_excelFile”)
Dim targetWorkbook As Microsoft.Office.Interop.Excel.Workbook = excel.Workbooks.Open(“str_excelFile2”)
Dim sourceSheet As Microsoft.Office.Interop.Excel.Worksheet = CType(sourceWorkbook.Worksheets(“Sheet1”), Microsoft.Office.Interop.Excel.Worksheet)
Dim targetSheet As Microsoft.Office.Interop.Excel.Worksheet = CType(targetWorkbook.Worksheets(“Sheet2”), Microsoft.Office.Interop.Excel.Worksheet)
Dim targetCell As Microsoft.Office.Interop.Excel.Range = targetSheet.Range(“A4”)
Dim sourcePivotTable As Microsoft.Office.Interop.Excel.PivotTable = CType(sourceSheet.PivotTables(1), Microsoft.Office.Interop.Excel.PivotTable)
sourcePivotTable.TableRange1.Copy()
targetWorkbook.Activate()
targetSheet.Activate()
targetCell.PasteSpecial(Paste:=Microsoft.Office.Interop.Excel.XlPasteType.xlPasteAll)
excel.CutCopyMode = Microsoft.Office.Interop.Excel.XlCutCopyMode.xlCopy

But as you might guess it’s not working, that’s why I’m here.

If someone could help me finding a solution I’d be thanksfull !

@oorvasi.sooprayen

Have a nice day,

Hi, do you have an example you can share to have a better idea?

I don’t have the Pivot table that will be used so I made a short one, and for the moment I only have an invoke code with this code inside.
There is no wokflow or Excel file of importance to share :frowning: