我希望 MsgBox 显示“msoPictureAutomatic”而不是“1”

问题描述 投票:0回答:1

我希望 MsgBox 向我显示 msoPictureAutomatic 而不是 1

因为我想得到一个名称而不是

请注意,1 表示 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

这是对象浏览器的图片

enter image description here

excel vba objectbrowser
1个回答
0
投票

您在 MsgBox 中看到值“1”而不是“msoPictureAutomatic”的原因是因为 MsgBox 函数默认显示常量的数值。

以下是如何修改代码以显示“msoPictureAutomatic”:

子宏1()

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

' 此 MsgBox 显示 msoPictureAutomatic 而不是 1 MsgBox Sheets(1).Shapes("Picture1").PictureFormat.ColorType & vbCrLf & "msoPictureAutomatic"

结束子

在修改后的代码中,我们在 MsgBox 语句中添加了 & vbCrLf & "msoPictureAutomatic"。这会将 Sheets(1).Shapes("Picture1").PictureFormat.ColorType(即 1)的结果与回车符 (vbCrLf) 和字符串“msoPictureAutomatic”连接起来。结果是一个 MsgBox,在单独的行上显示“1”,后跟“msoPictureAutomatic”。

© www.soinside.com 2019 - 2024. All rights reserved.