前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >EXCELVBA取税务局下载的文件名中名单与身份证号并配匹单位名称

EXCELVBA取税务局下载的文件名中名单与身份证号并配匹单位名称

作者头像
哆哆Excel
发布2022-10-25 13:19:23
2630
发布2022-10-25 13:19:23
举报
文章被收录于专栏:哆哆Excel

EXCELVBA取税务局下载的文件名中名单与身份证号并配匹单位名称

'打开文件对话框,选定文件夹,得出所有文件名(只有文件名)

Sub PFL() 'return file names under specific folder

'Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents

Dim fp, Fname As String, i As Integer, obmapp As Object

Dim dicTemp As Object

Set dicTemp = CreateObject("Scripting.Dictionary")

Application.ScreenUpdating = False

ti = Timer()

With Sheets("源数据")

For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row

ts = .Cells(i, 4)

If ts <> "" Then

dicTemp(ts) = .Cells(i, 2)

End If

Next i

End With

i = 2

Set obmapp = CreateObject("Shell.Application").BrowseForFolder(0, "请选择目录", 0, ThisWorkbook.Path)

If Not obmapp Is Nothing Then

fp = obmapp.self.Path & "\*.*"

Else

MsgBox "你没有选择任何目录"

Exit Sub

End If

Fname = Dir(fp)

Do While Fname <> ""

Cells(i, 1) = Left(Fname, Len(Fname) - 4)

k = InStr(Fname, "【")

j = InStr(Fname, "】_【")

p = InStr(Fname, "】的")

Cells(i, 2) = Mid(Fname, k + 1, j - k - 1)

Cells(i, 3).NumberFormatLocal = "@"

d = Mid(Fname, j + 3, p - j - 3)

Cells(i, 3) = d

If dicTemp.Exists(d) Then

Cells(i, 4) = dicTemp(d)

Else

Cells(i, 4) = ""

End If

Fname = Dir

i = i + 1

Loop

Application.ScreenUpdating = True

MsgBox "提取完成,时间为" & Format(Timer - ti, "00.00秒")

End Sub

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-06-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 哆哆Excel 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档