How to return the xlConstant for a number

  • Thread starter Thread starter Fred Holmes
  • Start date Start date
F

Fred Holmes

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
 
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.
 
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)
 
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
 
You have just been told twice that you don't.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top