ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to return the xlConstant for a number (https://www.excelbanter.com/excel-programming/322434-how-return-xlconstant-number.html)

Fred Holmes

How to return the xlConstant for a number
 
Is there a VBA function that will return the string name of a vba
constant from its number?

x = f(-4108)

would return

xlVAlignCenter

Thanks

Fred Holmes

Tim Williams

How to return the xlConstant for a number
 
There isn't a 1 to one mapping of numbers and strings in the application
context.

If you check in the object browser you will see that (for example) that both
"ap3D" (appearances) and "raNone" (arrowtypes) have a value of 1.

So you would also somehow have to define the specific context for your
constant.

Tim.




"Fred Holmes" wrote in message
...
Is there a VBA function that will return the string name of a vba
constant from its number?

x = f(-4108)

would return

xlVAlignCenter

Thanks

Fred Holmes




Bob Phillips[_6_]

How to return the xlConstant for a number
 
Don't think so Fred. Problem is that some number could be many constants,
such as 2 is xlBIFF, xlPublisher, xlMove, xlWIndows, etc., etc.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Fred Holmes" wrote in message
...
Is there a VBA function that will return the string name of a vba
constant from its number?

x = f(-4108)

would return

xlVAlignCenter

Thanks

Fred Holmes




Fred Holmes

How to return the xlConstant for a number
 
How do I set the context?

Dim cfv
cfv = ActiveCell.VerticalAlignment
MsgBox "Vertical Alignment is " & cfv

The above returns the message "Vertical Alignment is -4108"

I'd like to get to "Vertical Alignment is xlVAlign Center"

Thanks,

Fred Holmes



On Fri, 4 Feb 2005 14:07:24 -0800, "Tim Williams" <saxifrax at pacbell
dot net wrote:

There isn't a 1 to one mapping of numbers and strings in the application
context.

If you check in the object browser you will see that (for example) that both
"ap3D" (appearances) and "raNone" (arrowtypes) have a value of 1.

So you would also somehow have to define the specific context for your
constant.

Tim.




"Fred Holmes" wrote in message
.. .
Is there a VBA function that will return the string name of a vba
constant from its number?

x = f(-4108)

would return

xlVAlignCenter

Thanks

Fred Holmes




Bob Phillips[_6_]

How to return the xlConstant for a number
 
You have just been told twice that you don't.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Fred Holmes" wrote in message
...
How do I set the context?

Dim cfv
cfv = ActiveCell.VerticalAlignment
MsgBox "Vertical Alignment is " & cfv

The above returns the message "Vertical Alignment is -4108"

I'd like to get to "Vertical Alignment is xlVAlign Center"

Thanks,

Fred Holmes



On Fri, 4 Feb 2005 14:07:24 -0800, "Tim Williams" <saxifrax at pacbell
dot net wrote:

There isn't a 1 to one mapping of numbers and strings in the application
context.

If you check in the object browser you will see that (for example) that

both
"ap3D" (appearances) and "raNone" (arrowtypes) have a value of 1.

So you would also somehow have to define the specific context for your
constant.

Tim.




"Fred Holmes" wrote in message
.. .
Is there a VBA function that will return the string name of a vba
constant from its number?

x = f(-4108)

would return

xlVAlignCenter

Thanks

Fred Holmes






Dick Kusleika[_4_]

How to return the xlConstant for a number
 
Fred

This isn't simple, but here's a way: First dowload this workbook from
Chip's site

http://www.cpearson.com/Zips/TLIUtils.ZIP

(or navigate to http://www.cpearson.com/excel.htm and about 2/3 the way down
look for Download XLTLI - Type Lib Utilities)

Then, at the bottom of the standard module, put this code

Sub CCC()

Dim i As Long
Dim v As Collection

Set v = EnumValuesFromEnumGroup("XLValign", SearchXL)

For i = 1 To v.Count
Debug.Print v(i).ItemName, v(i).ItemValue
Next i

End Sub

You'll see all the enum names and values of type xlvalign. Now you just
need to work this into a function, which should be pretty easy. Post back
if you need more help, though.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Fred Holmes wrote:
Is there a VBA function that will return the string name of a vba
constant from its number?

x = f(-4108)

would return

xlVAlignCenter

Thanks

Fred Holmes





All times are GMT +1. The time now is 06:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com