Can somebody point out to me what is wrong with this?

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
Code:
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "Database").CreatePivotTable TableDestination:= _
        "[Thisworkbook.Name]Output!R12C1", TableName:="PivotTable1", _
        DefaultVersion:=xlPivotTableVersion10

This is part of the macro that runs on workbook_open event.

These is a debug error highlighting this par tof the code. I suspect it is particularly on the "Thisworkbook.Name" part.

I can't figure it out, help please.

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
That code is looking for a workbook actually called literally ThisWorkbook.Name.

If you want to actually put the workbook's name in the code try this.
Code:
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "Database").CreatePivotTable TableDestination:= _
        "[" & ThisWorkbook.Name & "]Output!R12C1", TableName:="PivotTable1", _
        DefaultVersion:=xlPivotTableVersion10
 
Upvote 0
That code is looking for a workbook actually called literally ThisWorkbook.Name.

If you want to actually put the workbook's name in the code try this.
Code:
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "Database").CreatePivotTable TableDestination:= _
        "[" & ThisWorkbook.Name & "]Output!R12C1", TableName:="PivotTable1", _
        DefaultVersion:=xlPivotTableVersion10

Thanks Norie, that solves it.
 
Upvote 0

Forum statistics

Threads
1,214,883
Messages
6,122,077
Members
449,064
Latest member
MattDRT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top