迭代VBA字典? [英] Iterate over VBA Dictionaries?

查看:143
本文介绍了迭代VBA字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MS运行时脚本库中使用Dictionary类来存储标签将要去报告模板的位置。有没有办法迭代该字典中的所有键值对,如Python?我只想使用键作为行号(这一切都在列A中),值将是标签头。

I'm using the Dictionary class in the MS Runtime Scripting library to store where labels are going to go for a report template. Is there a way to iterate over all the key value pairs in that dictionary like in Python? I just want to use the key as the row number (It's all going in column A) and the value will be the label header.

类似于:

For Each key in dict
    Range("A" & key).Value = dict(key)
Next key


推荐答案

尝试:

For Each strKey In oDic.Keys()
    Range("A" & strKey).Value = oDic(strKey)
Next

这篇关于迭代VBA字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆