Set dir = CreateObject("Scripting.Dictionary")
dir.Add "12", "layout1"
dir.Add "29", "layout2"
dir.Add "35", "layout3"
For Each slide In presentation.Slides
xyz = slide.Layout
msgBox dir.Item(xyz)
next
这里xyz将给出数字,我想将相同的值传递给目录对象以获取该键的值。但这里的问题是在dir.Item(xyz)如果我没有保持双引号到xyz然后我们没有得到该项的密钥因为它是systax问题,如果我保留双引号然后它将采取为xyz只是没有xyz的值。任何想法如何解决这个
答案 0 :(得分:1)
slide.Layout
返回数字,所以只需输入字典数字的键:
Set dir = CreateObject("Scripting.Dictionary")
dir.Add 12, "layout1"
dir.Add 29, "layout2"
dir.Add 35, "layout3"
For Each slide In presentation.Slides
MsgBox dir.Item(slide.Layout)
Next
您还可以将数字转换为字符串:
Set dir = CreateObject("Scripting.Dictionary")
dir.Add "12", "layout1"
dir.Add "29", "layout2"
dir.Add "35", "layout3"
For Each slide In presentation.Slides
MsgBox dir.Item(CStr(slide.Layout))
Next
但这只会增加代码的复杂性而不会获得任何东西。