getmail

Public Sub GetDataFromWord()
    AppSettings
    ‘On Error GoTo ErrHandler
    Dim StartTime, UsedTime As Variant
    StartTime = VBA.Timer
    ‘Input code here

    Dim Wb As Workbook
    Dim Sht As Worksheet
    Dim oSht As Worksheet
    Dim Rng As Range
    Dim Arr As Variant

    Dim Dic As Object
    Set Dic = CreateObject("Scripting.Dictionary")

    ‘Dim wdApp As Word.Application
    ‘Dim wdDoc As Word.Document
    Dim wdApp As Object
    Dim wdDoc As Object

    ‘Const SHEET_NAME As String = "提取信息"
    Set Wb = Application.ThisWorkbook
    Set Sht = Wb.Worksheets(1)

    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If wdApp Is Nothing Then
        Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0

    ‘Set wdApp = New Word.Application

    Filename = Dir(Wb.Path & "\*.doc*")
    Do While Filename <> ""
        Debug.Print Filename
        FilePath = Wb.Path & "\" & Filename
        Set wdDoc = wdApp.Documents.Open(FilePath)
        Text = wdDoc.Content.Text

        If RegTest(Text, "(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)") Then
            Arr = RegGetArray("(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)", Text)
            For i = LBound(Arr) To UBound(Arr)
                Key = CStr(Arr(i))
                Debug.Print Key
                If Not Dic.Exists(Key) Then
                    Dic(Key) = Dic.Count + 1
                End If
            Next i

        End If

        Filename = Dir
    Loop

    Application.StatusBar = ">>>>>>>>Regexpress Getting array >>>>>>>>"
    wdDoc.Close False    ‘关闭doc
    wdApp.Quit    ‘退出app
    Set wdApp = Nothing
    Set wdDoc = Nothing

    With Sht
        .Cells.ClearContents
        .Range("A1:B1").Value = Array("序号", "邮箱")
        Set Rng = .Range("A2")
        Set Rng = Rng.Resize(Dic.Count, 2)
        Rng.Value = Application.WorksheetFunction.Transpose(Array(Dic.Items, Dic.keys))

    End With

    UsedTime = VBA.Timer - StartTime
    Debug.Print "UsedTime:" & Format(UsedTime, "0.000 Seconds")
    ‘MsgBox "UsedTime:" & Format(UsedTime, "0.000 Seconds"), vbOKOnly, "QQ "
ErrorExit:
    Set Wb = Nothing
    Set Sht = Nothing
    Set Rng = Nothing

    Set Dic = Nothing

    AppSettings False

    On Error Resume Next
    wdApp.Quit

    Exit Sub
ErrHandler:
    If Err.Number <> 0 Then
        MsgBox Err.Description & "!", vbCritical, "QQ "
        Debug.Print Err.Description
        Err.Clear
        Resume ErrorExit
    End If
End Sub
Public Sub AppSettings(Optional IsStart As Boolean = True)
    If IsStart Then
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        Application.Calculation = xlCalculationManual
        Application.StatusBar = ">>>>>>>>Macro Is Running>>>>>>>>"
    Else
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
        Application.Calculation = xlCalculationAutomatic
        Application.StatusBar = False
    End If
End Sub
Public Function RegGetArray(ByVal Pattern As String, ByVal OrgText As String) As String()
    Dim Reg As Object, Mh As Object, OneMh As Object
    Dim Arr() As String, Index As Long
    Dim Elm As String
    Set Reg = CreateObject("Vbscript.Regexp")
    With Reg
        .MultiLine = True
        .Global = True
        .Ignorecase = False
        .Pattern = Pattern
        Set Mh = .Execute(OrgText)

        Index = 0
        ReDim Arr(1 To 1)
        For Each OneMh In Mh
            Index = Index + 1
            ReDim Preserve Arr(1 To Index)
            ‘If OneMh.submatches(0) <> "" Then Elm = OneMh.submatches(0)
            Arr(Index) = OneMh.submatches(0)

        Next OneMh
    End With
    RegGetArray = Arr
    Set Reg = Nothing
    Set Mh = Nothing
End Function
Public Function RegTest(ByVal OrgText As String, ByVal Pattern As String) As Boolean
‘传递参数 :原字符串, 匹配模式
    Dim Regex As Object
    Set Regex = CreateObject("VBScript.RegExp")
    With Regex
        .Global = True
        .Pattern = Pattern
    End With
    RegTest = Regex.TEST(OrgText)
    Set Regex = Nothing
End Function

  

时间: 2024-11-02 20:06:14

getmail的相关文章

mutt + getmail + msmtp + procmail配置

offlineimap 下载IMAP协议的邮件(Mutt内置的IMAP协议无法下载) getmail     下载POP3协议的邮件 procmail    过滤邮件 msmtp       发送邮件 安装: apt-get install mutt offlineimap getmail4 procmail msmtp 修改配置文件 ~/.muttrc set mbox_type=Maildir set folder=$HOME/.mail set spoolfile=~/.mail/ set

用户管理系统网站框架改进之MVC模式

从之前的用户管理系统中我们会发现,JSP主要是做界面的,但却用了JSP来对用户进行验证和分页处理,而Servlet处理页面的转跳是最快捷和最方便的,所以对用户管理系统的框架进行了改进,使用MVC模式. MVC是一种设计模式,它强制性的使应用程序的输入.处理和输出分开.使用MVC应用程序被分为三个核心部件:模型.视图和控制器.它们各自处理自己的任务. MVC的各个字母分别是M(model模型).V(view视图)和C(controller控制器) M主要由Java class来处理,也可以是Jav

001课-java_web开发入门

一.Tomcat服务器常见启动问题:(1).Java_home环境变量,由于tomcat服务器的bin目录中的一些jar文件必须使用到java类库,所以必须先配置Java_home环境变量.(2).端口占用问题(3).Catalina_home环境变量的问题,如果配置了catalina_home环境变量,则默认启动的是catalina_home所指向的tomcat服务器. 二.Tomcat目录结构:(1).bin:存放启动和关闭tomcat的脚本文件.(2).conf:存放tomcat服务器中的

JAVA学习第六十五课 — 正則表達式

正則表達式:主要应用于操作字符串.通过一些特定的符号来体现 举例: QQ号的校验 6~9位.0不得开头.必须是数字 String类中有matches方法 matches(String regex) 告知此字符串是否匹配给定的正則表達式. regex,就是给定的正則表達式 public static void checkQQ() { //第一位是数字1-9,第二位以后是0-9,除去第一位数剩下数字位数范围是5到8位 String regex = "[1-9][0-9]{5,8}";//正

Servlet—简单的管理系统

网站的框架 网站的框架采用MV模式,即Model(模型).View(视图).框架将界面层和模型层进行分离,结构更清晰,更加方便管理代码. 下面贴出网站详细的代码: 1.Login.java /** *登录界面*/ package com.xidian; import javax.servlet.http.*; import java.io.*; public class Login extends HttpServlet { public void doGet(HttpServletReques

hibernate外键一对一关联

两个实体类 package vo; public class message {private int mid;private String mname;private int age;private String mail;private String address;private String tel; private User user;public int getMid() { return mid;}public void setMid(int mid) { this.mid = m

Java Web开发常见问题

一.Tomcat服务器常见启动问题:(1).Java_home环境变量,由于tomcat服务器的bin目录中的一些jar文件必须使用到java类库,所以必须先配置Java_home环境变量.(2).端口占用问题(3).Catalina_home环境变量的问题,如果配置了catalina_home环境变量,则默认启动的是catalina_home所指向的tomcat服务器. 二.Tomcat目录结构:(1).bin:存放启动和关闭tomcat的脚本文件.(2).conf:存放tomcat服务器中的

5分钟教你配置命令行界面的163邮箱client

网易163免费邮箱相关server信息: mutt 是命令行下的邮件client,它仅是管理邮件的组织编辑,邮件的发送和接收须要调用相应的程序. 这里用的各自是getmail 和 msmtp. 过程例如以下 ===== 1. 安装mutt, getmail, msmtp ====================== $ sudo yum -y install mutt getmail msmtp 2. Build Mail Dir ================== Create ~/Mail

SQL练习

记得导包 /class TestUser package com.JDBCsql; import lombok.Data; @Data public class TestUser { private Integer id; private String name; private Integer pasword; private String mail; private String root; } /class TestMysql package com.JDBCsql; import jav