Optional not working in Excel 2007

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,072
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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