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

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,749
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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
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
 

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,749
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.
 

Forum statistics

Threads
1,136,518
Messages
5,676,324
Members
419,619
Latest member
jalme

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
Top