-3

I want MsgBox shows me msoPictureAutomatic instead of 1.

Because I want to get a enum name not a enum value.

Please note that 1 means msoPictureAutomatic

Sub Macro1()

Sheets(1).Pictures.Insert("C:\Users\George\Downloads\MyPicture.png").Name = "Picture1"

'This MsgBox shows me 1. 
'I want this MsgBox shows me msoPictureAutomatic.
MsgBox Sheets(1).Shapes("Picture1").PictureFormat.ColorType

End Sub

Please note that I gave msoPictureAutomatic and 1 for just an example. I am looking for a common solution. I am interested in any other values.

1

2 Answers 2

0

The property you are looking at (and most other like it) contain number values.

MsoColorType.msoPictureAutomatic and other enums are used to provide easy to read code etc at design time.

There is no backwards enumeration for these values.

You need to determine all the values you want the text version for, and create a function to map them to the value.

Example:

Function LookupMsoPictureColorType(Value As Variant)
Dim Result As String: Result = "Unknown Value"
Select Case Value
Case MsoPictureColorType.msoPictureAutomatic
    Result = "MsoPictureColorType.msoPictureAutomatic"
Case MsoPictureColorType.msoPictureBlackAndWhite
    Result = "MsoPictureColorType.msoPictureBlackAndWhite"
End Select
LookupMsoPictureColorType= Result
End Function

You will need to create something like this for every class you want too do this for too as many enums have the value 1 (eg MsoColorType.msoColorTypeRGB)

Sign up to request clarification or add additional context in comments.

1 Comment

Then you've answered your own question. There is no solution for every situation.
-1

The reason you are seeing the value "1" instead of "msoPictureAutomatic" in your MsgBox is because the MsgBox function displays the numerical value of the constant by default.

Here's how you can modify your code to display "msoPictureAutomatic" instead:

Sub Macro1()

Sheets(1).Pictures.Insert("C:\Users\George\Downloads\MyPicture.png").Name = "Picture1"

' This MsgBox shows msoPictureAutomatic instead of 1 MsgBox Sheets(1).Shapes("Picture1").PictureFormat.ColorType & vbCrLf & "msoPictureAutomatic"

End Sub

In the modified code, we've added & vbCrLf & "msoPictureAutomatic" to the MsgBox statement. This concatenates the result of Sheets(1).Shapes("Picture1").PictureFormat.ColorType (which is 1) with a carriage return (vbCrLf) and the string "msoPictureAutomatic". The result is a MsgBox that displays "1" followed by "msoPictureAutomatic" on separate lines.

1 Comment

Technically, it does exactly what you asked for. Your question does not state that you are interested in any other values.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.