Compile Error on WB Close ONLY

Toby Corner

New Member
Joined
Oct 23, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have an old (97-2003) Excel workbook I'm converting to new version in Office 365. I've saved down as new file version, and VB compiles fine and all works within the workbook, but when I close the file it gives the below:

1603443118424.png


Note that cmbSeason is a COmboBox created in Developer > Design mode - looks like the following:

1603443239011.png


Running the macro whilst workbook is open is absolutely fine so getting confused as to why it only seems to cause an issue on closing the file. Any ideas?

Toby
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Welcome to MrExcel

Converting a file that old may give you many other problems in future
- too much has changed in Excel and it is still changing at a rapid rate
Consider creating a new workbook and rebuilding from the ground up (step by step) rather than converting
- converting is a compromise that you may seriously regret later


In the meantime ...
Is that code in a SHEET code window or in a Module?
 
Upvote 0
Welcome to MrExcel

Converting a file that old may give you many other problems in future
- too much has changed in Excel and it is still changing at a rapid rate
Consider creating a new workbook and rebuilding from the ground up (step by step) rather than converting
- converting is a compromise that you may seriously regret later


In the meantime ...
Is that code in a SHEET code window or in a Module?
The code is in a SHEET code window, not a module.
 
Upvote 0
How are you using Sheet3?
- is it the sheet's VBA codename?
- or is it a sheet variable declared in your macro?

What is the TAB name of that sheet?

Is the code in Sheet3's code window or in a different sheet?

If you do not understand my question, please post an image as below from VBA to help
SheetName.jpg
 
Upvote 0
How are you using Sheet3?
- is it the sheet's VBA codename?
- or is it a sheet variable declared in your macro?

What is the TAB name of that sheet?

Is the code in Sheet3's code window or in a different sheet?

If you do not understand my question, please post an image as below from VBA to help
View attachment 24721
TABNAME is "Costings", screenshot to confirm. And yes the code is on Sheet3s window:

1603463028218.png

How are you using Sheet3?
- is it the sheet's VBA codename?
- or is it a sheet variable declared in your macro?

What is the TAB name of that sheet?

Is the code in Sheet3's code window or in a different sheet?

If you do not understand my question, please post an image as below from VBA to help
View attachment 24721

I have replaced Sheet3 with Sheets("Costings") in every instance and I no longer get the issue - excellent suspicions!! The Sheet3 way of referencing must be an older version thing perhaps.

Thanks so much, rebuilding would not have been a great option as it is a mammoth s/sheet.
 
Upvote 0
Glad my questions pointed you in the correct direction

The code is in the sheet code of sheet "Costings". Both of these methods should also behave correctly:

Below, VBA should interpret Me as Sheet "Costings"
VBA Code:
Me.Cells(1, 3)= Me.cmbSeason.Value

Because the code is in the sheet code window, VBA assumes that an unreferenced object is also in that sheet. Me can be helpful to clarify things in the code but is in fact not required.
VBA Code:
Cells(1, 3)= cmbSeason.Value
 
Upvote 0
Solution
Glad my questions pointed you in the correct direction

The code is in the sheet code of sheet "Costings". Both of these methods should also behave correctly:

Below, VBA should interpret Me as Sheet "Costings"
VBA Code:
Me.Cells(1, 3)= Me.cmbSeason.Value

Because the code is in the sheet code window, VBA assumes that an unreferenced object is also in that sheet. Me can be helpful to clarify things in the code but is in fact not required.
VBA Code:
Cells(1, 3)= cmbSeason.Value
Again, many thanks!
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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