Anyone have any idea why xlMedium is -4138?
xlHairline = 1
xlThin = 2
xlMedium = -4138
xlThick = 3
The programmer must have been drunk the day he wrote those constants.
Printable View
Anyone have any idea why xlMedium is -4138?
xlHairline = 1
xlThin = 2
xlMedium = -4138
xlThick = 3
The programmer must have been drunk the day he wrote those constants.
The same name (xlMedium) was probably used for another set of constants before it was used for xlBorderWeight - and as each name can only have one value, the value had to stay what it was previously.
It doesn't actually matter much tho, as you should just use the constants anyway.. but it does mean that if you really want to work with the values instead then your code becomes more complex.
I was doing some automation that draws some "graphics" by coloring in cells and setting their borders. I have an ini file with the border width. I decided to write a function to convert from my values (1 through 4) to the Excel border weight constants, just in case they decide Excel is too slow at drawing and I rewrite that portion to use GDI.
I see.. well calling functions is slow, so (as your values are in a small range) I'd recommend using an array instead, eg:
Then in your code, this array would be used in the same way as the function would be.Code:Dim BorderWidthToBorderWeight(1 to 4) as Long
BorderWidthToBorderWeight(1) = xlHairline
BorderWidthToBorderWeight(2) = xlThin
BorderWidthToBorderWeight(3) = xlMedium
BorderWidthToBorderWeight(4) = xlThick