将文件导入excel工作簿,然后处理文件并复制到另一个工作簿中

时间:2018-07-31 16:25:15

标签: vba excel-vba

我想创建一个子目录,该子目录允许用户选择目录,在目录中搜索给定的文件类型,将给定类型的数据导入电子表格以进行数据处理,然后获取处理后的数据并将其写入数据日志电子表格以进行简单分析。

我要尝试实现的其他功能是使用 def printSet(): for user in range (0,len(parsed_json['members'])-1): userDict=parsed_json['members'][user]#Catches errors resulting from users not having all settings configured try: print("id: "+userDict["id"]) except KeyError: print("No ID found") try: print("team id: "+userDict["team_id"]) except KeyError: print("No team ID found") try: print("name: "+userDict["name"]) except KeyError: print("No name found") try: print("real name: "+userDict["real_name"]) except KeyError: print("No real name found") userProf=userDict['profile'] try: print("title: "+userProf["title"]) except KeyError: print("No title found") try: print("real name: "+userProf["real_name"]) except KeyError: print("No real name found") try: print("real name normalized: "+userProf["real_name_normalized"]) except KeyError: print("No real name normalized found") try: print("display name: "+userProf["display_name"]) except KeyError: print("No display name found") try: print("display name normalized: "+userProf["display_name_normalized"]) except KeyError: print("No display name normalized found") try: print("email: "+userProf["email"]) except KeyError: print:("No email found") try: print("first name: "+userProf["first_name"]) except KeyError: print("No first name found") try: print("last name: "+userProf["last_name"]) except KeyError: print("No last name found") #To easily show when one member ends and another begins print("----------------------------------") printSet() 而不是FileSystemObject来标识要循环通过的目录。

Application.FileDialog

1 个答案:

答案 0 :(得分:0)

我花了比预期更长的时间来编写此代码,但是我想发布它,因为我找不到使该代码正常工作所需的工具。欢呼,感谢您的反馈!

为了使用FSO,我用以下代码替换了FileDialog方法:

Dim objFSO as new FileSystemObject Dim objStartFolder as Folder Dim objFolder as Folder Dim colFiles as Collection set objFSO = createobject("Scripting.FileSystemObject") objStartFolder = "\\folder" set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files For i=1 to colFiles.count run csv_get and nextline next i Subfolder_Search objFSO.GetFolder(objStartFolder) function Subfolder_Search(folder) For i=1 to Folder.SubFolders.count Set objFolder = objFSO.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files For i=1 to colFiles.count run csv_get and nextLine Next i Subfolder_Search Subfolder Next i end function