VBA Finding ‘Constant’ name if number & Enumerated data type

BruceMutton

New Member
Joined
Feb 16, 2002
Messages
10
The intrinsic constant data types, such as xlCVError or xlPaperSize are like collections in concept I think, however I do not seem to be able to use collection syntax, such as xlPaperSize.Count or For Each lngConst In xlPaperSize......

The problem I am trying to solve is...
Let PSize = WorkSheets(1).PageSetup.PaperSize
'PSize as returned is a Double or Long integer number, this functions OK
'Now I want to find the text string of the intrinsic constant that evaluates to this number, PSize
'ie is the paper size "xlA4", "xlLetter", "xlUser" or any other of the 50 or so paper size constants??

Suggestions much appreciated
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi

I might be missing your request here, but do this.

Go into your object browser,
search fo papersize

All of the constants will be listed to the right.

As you click on any constant,
the number will be displayed on the bottom
left above the file reference
This message was edited by TsTom on 2002-03-22 02:21
 
Upvote 0
Hi Bruce

Firstly the XlPaperSize is a Property and not an Object as so is not part of any Collection, or a Collection itself.

The "For Each" loop can only be used on a collection of Objects with a single Object variable as the Object or an array.

But to answer you question the best thing maybe to simply copy the Constants from the "PaperSize Property" in the VBE help to a Worksheet, place a number next to each on the right in the order they appear. Then simply use either the Vlookup WOrksheetFunction to ascociate the Integer returned and/or use a simple loop to go through each cell.
 
Upvote 0
TsTom, Dave
Thanks, I was on to those, just hoping there was a more direct way of returning the text names at runtime
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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