Sub TransferData()

    AppSettings
Dim StartTime As Variant
Dim UsedTime As Variant
StartTime = VBA.Timer On Error GoTo ErrHandler Dim dHas As Object
Dim dNew As Object
Dim Key As String
Dim OneKey Dim Wb As Workbook
Dim Sht As Worksheet
Dim oSht As Worksheet
Dim OpenWb As Workbook
Dim OpenSht As Worksheet
Dim NewWb As Workbook
Dim NewSht As Worksheet
Dim EndRow As Long, EndCol As Long
Dim i As Long, j As Long
Dim FolderPath As String
Dim FilePath, FilePaths, sMail, arMail, OneAr
Dim MailContent, PhoneContent MailContent = ""
PhoneContent = "" Set dNew = CreateObject("Scripting.Dictionary")
Set dHas = CreateObject("Scripting.Dictionary")
Set Wb = Application.ThisWorkbook
Set Sht = Wb.Worksheets("邮箱列表")
With Sht
EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
If EndRow > 1 Then
Set Rng = .Range("A1").Resize(EndRow, 1)
Arr = Rng.Value
For i = LBound(Arr) To UBound(Arr)
Key = CStr(Arr(i, 1))
dHas(Key) = ""
Next i
End If
End With FolderPath = Wb.Path & "\表格一\"
FilePaths = FsoGetFiles(FolderPath, "*.xls*")
If FilePaths(1) = "None" Then GoTo ErrorExit For Each FilePath In FilePaths
Set OpenWb = Application.Workbooks.Open(FilePath)
Set OpenSht = OpenWb.Worksheets(1)
With OpenSht
EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range("A3:J" & EndRow)
Arr = Rng.Value
For i = LBound(Arr) To UBound(Arr)
sMail = Arr(i, 10)
If Len(sMail) > 0 Then
sMail = Left(sMail, Len(sMail) - 1)
arMail = Split(sMail, ";")
For Each OneAr In arMail
'Debug.Print " OneAr>"; OneAr
Key = RegGet(OneAr, "(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)")
If Len(Key) > 0 Then
'Debug.Print "Key>"; Key
'Debug.Print ">>>>"; Key; " > "; Arr(i, 2); " > "; Arr(i, 1)
dNew(Key) = Array(Key, Arr(i, 2), Arr(i, 1))
MailContent = MailContent & vbCrLf & Key
End If
Next OneAr
End If sPhone = Arr(i, 7)
If Len(sPhone) > 0 Then
sPhone = Left(sPhone, Len(sPhone) - 1)
arPhone = Split(sPhone, ";")
For Each OneAr In arPhone
Key = RegGet(OneAr, "(1\d{10})")
If Key <> "" Then PhoneContent = PhoneContent & vbCrLf & Key
Next OneAr
End If 'If i = 10 Then Exit For
Next i
End With
OpenWb.Close False
Next FilePath '对比去重
For Each OneKey In dHas.keys
If dNew.exits(OneKey) Then dNew.Remove (OneKey)
Next OneKey Set oSht = Wb.Worksheets("_人地址薄")
FilePath = Wb.Path & "\表格二\导出文件" & Format(Now, "yyyymmdd-hhmm") & ".xlsx" Set NewWb = Application.Workbooks.Add
NewWb.SaveAs FilePath oSht.Copy before:=NewWb.Worksheets(1)
Set NewSht = NewWb.Worksheets("_人地址薄")
With NewSht
Set Rng = .Range("A2")
Set Rng = Rng.Resize(dNew.Count, 3)
Rng.Value = Application.Rept(dNew.Items, 1)
End With On Error Resume Next
NewWb.Worksheets(2).Delete
On Error GoTo 0 NewWb.Save
NewWb.Close False PhoneFilePath = Wb.Path & "\txt\导出手机" & Format(Now, "yyyymmdd-hhmm") & ".txt"
PhoneContent = Mid(PhoneContent, 2)
NewTextFile PhoneFilePath, PhoneContent MailFilePath = Wb.Path & "\txt\导出邮箱" & Format(Now, "yyyymmdd-hhmm") & ".txt"
MailContent = Mid(MailContent, 2)
NewTextFile MailFilePath, MailContent With Sht
Set Rng = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
Set Rng = Rng.Resize(dNew.Count, 3)
Rng.Value = Application.Rept(dNew.Items, 1)
.Range("B:C").ClearContents
End With UsedTime = VBA.Timer - StartTime
Debug.Print "UsedTime :" & Format(UsedTime, "#0.0000 Seconds")
'MsgBox "UsedTime :" & Format(UsedTime, "#0.0000 Seconds") ErrorExit: Set dHas = Nothing
Set dNew = Nothing
Set Wb = Nothing
Set NewWb = Nothing
Set OpenWb = Nothing
Set Sht = Nothing
Set oSht = Nothing
Set OpenSht = Nothing
Set NewSht = Nothing AppSettings False
Exit Sub
ErrHandler:
If Err.Number <> 0 Then
MsgBox Err.Description & "!", vbCritical, "AuthorQQ 84857038"
Debug.Print Err.Description
Err.Clear
Resume ErrorExit
End If End Sub
Public Sub AppSettings(Optional IsStart As Boolean = True)
Application.ScreenUpdating = IIf(IsStart, False, True)
Application.DisplayAlerts = IIf(IsStart, False, True)
Application.Calculation = IIf(IsStart, xlCalculationManual, xlCalculationAutomatic)
Application.StatusBar = IIf(IsStart, ">>>>>>>>Macro Is Running>>>>>>>>", False)
End Sub Function FsoGetFiles(ByVal FolderPath As String, ByVal Pattern As String, Optional ComplementPattern As String = "") As String()
Dim Arr() As String
Dim FSO As Object
Dim ThisFolder As Object
Dim OneFile As Object
ReDim Arr(1 To 1)
Arr(1) = "None"
Dim Index As Long
Index = 0
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error GoTo ErrorExit
Set ThisFolder = FSO.getfolder(FolderPath)
If Err.Number <> 0 Then Exit Function
For Each OneFile In ThisFolder.Files
If OneFile.Name Like Pattern Then
If Len(ComplementPattern) > 0 Then
If Not OneFile.Name Like ComplementPattern Then
Index = Index + 1
ReDim Preserve Arr(1 To Index)
Arr(Index) = OneFile.Path
End If
Else
Index = Index + 1
ReDim Preserve Arr(1 To Index)
Arr(Index) = OneFile.Path
End If
End If
Next OneFile
ErrorExit:
FsoGetFiles = Arr
Erase Arr
Set FSO = Nothing
Set ThisFolder = Nothing
Set OneFile = Nothing
End Function
Public Function RegGet(ByVal OrgText As String, ByVal Pattern As String) As String
Dim Regex As Object
Dim Mh As Object
Set Regex = CreateObject("VBScript.RegExp")
With Regex
.Global = True
.Pattern = Pattern
End With
If Regex.test(OrgText) Then
Set Mh = Regex.Execute(OrgText)
RegGet = Mh.Item(0).submatches(0)
Else
RegGet = ""
End If
Set Regex = Nothing
End Function
Sub NewTextFile(ByVal FilePath As String, ByVal FileContent As String)
Open FilePath For Output As #1
Print #1, FileContent
Close #1
End Sub

  

20181011xlVba提取邮箱手机号码的更多相关文章

  1. python从Excel中提取邮箱

    从各个城市的律师协会去爬取的律师的招聘信息,可是邮箱在招聘简介里面,所有需要写个脚本去提取邮箱 import pandas as pd import re regex = r"([-_a-z ...

  2. 快速提取邮箱地址(利用word或网站)

    在word中,CTRL+F,输入:[A-z,0-9]{1,}\@[A-z,0-9,\.]{1,} 点击“高级”,勾选“使用通配符”,点击“查找全部”: 复制.粘贴. 还可通过以下页面在线提取. htt ...

  3. 小程序[邮箱提取器-EmailSplider]总结

    1.背景情况     学东西做快的是付诸实践,写这个小程序的目的就是为了综合运用各个知识点,从而提升学习的效果.   2.涉及知识     A.Swing 的布局     B.Swing中,线程访问U ...

  4. 提取包含QQ的文本为QQ邮箱

    # -*- coding: utf-8 -*- """ Created on Sun Dec 15 14:08:03 2019 @author: Dell 提取包含QQ号 ...

  5. 如何从OA系统批量整理出邮箱地址,并导入到Foxmail 地址薄中?

    一.打开某位leader的OA,点击查看“下属” a. 将所有的下属信息 --- 全选 --- 复制 --- 粘贴到 excel 表格中 b. 分别提取“姓名” 和 “邮箱”地址信息,结合notepa ...

  6. 2019-01-31 Python学习之BFS与DFS实现爬取邮箱

    今天学习了python网络爬虫的简单知识 首先是一个爬取百度的按行读取和一次性爬取 逐行爬取 for line in urllib.request.urlopen("http://www.b ...

  7. 常用的jquery

    获取一组radio被选中项的值 var item = $('input[@name=items][@checked]').val(); 获取select被选中项的文本 var item = $(&qu ...

  8. JQuery 常用命令总结

    下面介绍在jQuery中设置form表单中action的值的方法. $("#myFormId").attr("action", "userinfo.s ...

  9. MySQL 第八天(核心优化二)

    一.昨天内容回顾 存储引擎 保存数据的格式(技术),不同格式体现特性不一样 myisam ① 结构.数据.索引 文件单独存储 ② 存入数据顺序(不考虑主键顺序) ,写入数据速度快 ③ 并发性,低,锁整 ...

随机推荐

  1. 【Python57--正则1】

    一.正则表达式匹配IP地址 1.search()方法:用于在字符串中搜索正则表达式模式第一次出现的位置 >>> import re >>> re.search(r' ...

  2. Bootstrap3基础 container 浏览器宽度与容器宽度的四种配合

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  3. Android灯光系统--通知灯深入分析【转】

    本文转自:https://www.cnblogs.com/lkq1220/p/6406261.html Android灯光系统--通知灯深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 ...

  4. POJ 1873 The Fortified Forest(凸包)题解

    题意:二维平面有一堆点,每个点有价值v和删掉这个点能得到的长度l,问你删掉最少的价值能把剩余点围起来,价值一样求删掉的点最少 思路:n<=15,那么直接遍历2^15,判断每种情况.这里要优化一下 ...

  5. Python SSH爆破以及Python3线程池控制线程数

    源自一个朋友的要求,他的要求是只爆破一个ip,结果出来后就停止,如果是爆破多个,完全没必要停止,等他跑完就好 #!usr/bin/env python #!coding=utf-8 __author_ ...

  6. Cannot retrieve metalink for repository: epel 错误解决办法

    centos下安装完EPEL源, 然后更新一下yum缓存, 如果发现这样的错误:Error: Cannot retrieve metalink for repository: epel. Please ...

  7. 关于COM类工厂80070005和8000401a错误分析及解决办法

    关于COM类工厂80070005和8000401a错误分析及解决办法 看到很多相关的文章,第一次配置配置时没有啥作用,让别人来解决的,可惜不晓得他怎么解决的,当我再次遇到时,不得不硬着头皮去解决. 总 ...

  8. oracle 之 基础操作

    //删除存在的表空间及数据 drop tablespace TS_YYGL including contents and datafiles 若是出现了提示 错误 导致无法全部删除,那么就执行以下语句 ...

  9. 51nod 1275 连续字段的差异(单调队列)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1275 题意: 思路: 固定某个端点,然后去寻找满足能满足要求的最大区间, ...

  10. JavaScript中 call和apply

    call()方法和apply()方法的作用相同,他们的区别在于接收参数的方式不同. 对于call(),第一个参数是this值没有变化,变化的是其余参数都直接传递给函数.(在使用call()方法时,传递 ...