Sheet in VBAProject gets copied and converted into ThisWorkbook

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
3,212
Office Version
  1. 365
Platform
  1. Windows
I'm having a problem with one particular workbook. I have a worksheet with a table that is 916 columns by 126 rows. In the VBA project I had changed the Code name to CostDetails.

Somehow, the sheet got copied twice only in VBAproject. The Code Names for the two copies are CostDetails and CostDetails1 and then the real sheet code name got changed to CostDetails11. All the sheet code moved into CostDetails1. When I click the two copies, the properties window shows the name for both as ThisWorkbook.

This happened once before on this workbook. I spent a huge amount of time making a duplicate from scratch by copying the values and adding the cell formats & formulas manually.

In the snapshot below, you can see that I changed the code name of the real sheet to CostDetSht to temporarily solve the problem.

Does anyone know of a way to fix this and prevent this?

UPDATE: It seems to keep making copies if I change the code name of the REAL sheet

1681393926057.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
That is weird! As you can see from the icons, it indeed looks like they are aliases of ThisWorkbook. How that is possible??
Perhaps a private message to one of the MVPs on the forum? They might understand the structure of a workbook better
 
Upvote 0
Update: I've tried so many things so I'm not sure if this one process solved it or if it's because I tried several things.

I saved the file as .XLSX (this removed my vba code and my custom UI for the ribbon menu)
Closed and Reopened
Deleted all my named ranges including references to external workbooks (excluding table references)
Deleted all my Conditional formatting
Saved, closed and reopened
Copied all my code back into standard modules, sheet modules, and the workbook module
Added my custom UI ribbon menu back in
Recreated all my conditional formatting

It's been working for about 10 ten days without creating psuedo versions of Thisworkbook.
 
Upvote 0
This continues to happen even though I changed my "Excel Tables" to regular ranges. I split up my really large table to two smaller ones. Each of those tables are over 500 columns and 340 rows. Now I have 5 different "ThisWorkbook" objects.

Does anybody have a reason why this happens?

In my VBA code I use the CodeName of the sheets because the regular sheet names may change. When this problem happens, it changes the CodeName each time and it also removes the code in those sheets and moves them to the new funky sheets.

1684940698208.png
 
Upvote 0
I came across this, but it didn't resolve the issue for me
Redirecting

The only way to fix this as described above is to save as .XLSX, Save again as .XLSM, then copy all the VBA code into the proper places from the original file.
 
Upvote 0
Every time I cycle a Save, Close, and reopen, the number of copies of my 2 sheets gets larger and renamed. I have no structured Excel tables on them anymore, so that can't be the cause. Each sheet has about 43,000 formula cells.

1686604088599.png
 
Upvote 0
Thanks for that Link Mark. I've seen similar things. Based on one of the fixes, I think I'll copy the "xl/vbaProject.bin" from a good working version of this WB and save it for later.

I have been able to temporarily fix the issue, but I'd like to know how to prevent it from happening in the first place. One of the people in the thread said they were sending a sheet object to a standard module SUB, and THAT what was causing the issue. I don't have any calls like that.

What have I learned:
To fix the issue: Save as .XLSX and close. Open .XLSX, copy all the VBA code from the old (.XLSM), save as new .XLSM. All custom UI Ribbon information persists in .XLSX.
I am monitoring a way to prevent this: After saving as .XLSB I have yet to see any new extra Sheets as Thisworkbook objects. I will keep you posted

Does anybody know of any drawbacks to using .XLSB vs .XLSM?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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