Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return Number George Excel Discussion (Misc queries) 2 March 3rd 09 05:49 PM
Return the Row number Kenneth Excel Discussion (Misc queries) 3 November 19th 08 08:45 AM
VBA: how do I return a row number? Mcasteel[_23_] Excel Programming 1 November 1st 04 09:30 PM
return row number Jonathan Vickers Excel Programming 3 February 22nd 04 12:18 AM
command to return the row number or cell number in excel? desmondleow[_5_] Excel Programming 1 December 11th 03 10:51 AM


All times are GMT +1. The time now is 01:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"