Optional not working in Excel 2007

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,051
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Code:
Sub DoComment(r As Range, T, Optional Append = False, Optional theSize = 10)

After much debugging, I find theSize above is NOT 10 !!!
Just confirmed by stepping.

It works correctly in Excel 2003.

Can I fix it ? Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Not sure what you are doing but are you changing the value of the theSize argument inside the DoComment Sub ?

Try passing the argument ByVal and see if it makes any difference :

Sub DoComment(r As Range, T, Optional Append = False, Optional ByVal theSize = 10)
 
Upvote 0
This is really weird!
I wasn't changing theSize, for testing there was a Stop on the first line in DoComment, and I was running the mouse over the variable name. The balloon showed 'Empty'.
So I added ByVal and it worked. Then I removed ByVal out to recheck, and it still worked.

The size being empty brought up an Application Defined Error 'Unable to Set the Size of the Font Class". This was fixed by hard coding a size.
Thanks for suggesting ByVal, and all seems ok now... but a bit worrying !
 
Upvote 0
This is really weird!
I wasn't changing theSize, for testing there was a Stop on the first line in DoComment, and I was running the mouse over the variable name. The balloon showed 'Empty'.
So I added ByVal and it worked. Then I removed ByVal out to recheck, and it still worked.

The size being empty brought up an Application Defined Error 'Unable to Set the Size of the Font Class". This was fixed by hard coding a size.
Thanks for suggesting ByVal, and all seems ok now... but a bit worrying !

That's weird.. It should have the value set by default in the sub definition.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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