将VBA字典写入文本文件 [英] Write VBA Dictionary to text file

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

问题描述

我将twitter搜索api结果存储为Excel VBA词典.我想将字典写到一个文本文件中.我怎么做?

I have the twitter search api results stored as an Excel VBA Dictionary. I would like to write the dictionary to a text file. How do I do that?

推荐答案

假定此字典中的键值为字符串,则可以调用这样的函数,然后使用FileSystemObject或其他方法来创建和编写文本文件(例如,此处).

Assuming the keys and values in this dictionary are string, you could call a function like this and then use FileSystemObject or other method to create and write a textfile (example here).

只需将字典对象传递给FSO.WriteFile行中的函数,例如:

Simply pass your dictionary object to the function in the FSO.WriteFile line like:

Dim fso as Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile as Object
Set oFile = FSO.CreateTextFile("C:\desktop\textfile.txt") 'Modify as needed
oFile.Write PrintDictionary(twitter_dictionary)           'modify as needed
set fso = Nothing: set oFile = Nothing

这是函数:

Function PrintDictionary(dict as Object) As String

Dim k as Variant
Dim i as Long
Dim fullText as String

For each k in dict.Keys()
    fullText = fullText & k & vbTab & dict(k) & vbCrLF
Next

PrintDictionary = fullText

End Function

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

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