VBA 宏 - 日常积累

EXL 202105 自动检查输入 - DLP

Sub AutoFill()

'自动填充
Dim q As Long
    q = Application.WorksheetFunction.CountA(Sheet1.Range("E:E"))
    
    Range("L3").FormulaR1C1 = _
        "=IF(RC[-10]="""","" "",RC[-10]&""|""&RC[-9]&""|""&RC[-8]&""|""&RC[-7]&""|""&RC[-6]&""|""&RC[-5]&""|""&RC[-4])"
    
    Range("L3").Select
    Selection.AutoFill Destination:=Range("L3:L" & q)

'表头补充
    Range("J1").Select
    ActiveCell.FormulaR1C1 = "=COUNTA(C[-5])-2"
    Range("K2").Select
    ActiveCell.FormulaR1C1 = "=""TRL""&REPT(""0"",9-LEN(R[-1]C[-1]))&R[-1]C[-1]"
    Range("L2").Select
    ActiveCell.FormulaR1C1 = _
        "=""HDR""&TEXT(TODAY(),""YYYYMMDD"")&REPT(""0"",9-LEN(R[-1]C[-2]))&R[-1]C[-2]"
    Range("L3").Select

End Sub


Sub A_检查()

Dim StartTime As Double
Dim SecondsElapsed As Double

'Remember time when macro starts
  StartTime = Timer

'********************************************************************************************************************

Application.ScreenUpdating = False '//关闭屏幕刷新
Application.Calculation = xlCalculationManual '手动重算

'=====
Dim q As Long, w As String, e As String
    q = 3
    Do While Range("E" & q).Value <> blank
        w = Range("B" & q).Value & Range("F" & q).Value
        If w = "C01Same Contact" Or _
                w = "C02Fail PSB check " Or _
                w = "C02ID Expire" Or _
                w = "C03AML High Risk Not Contactable" Or _
                w = "C03AML Batch Screening Not Contactable" Or _
                w = "C03Screening red flag true match" Or _
                w = "C03Multiple CIF" Or _
                w = "C04PAT testing - Fail PSB check" Or _
                w = "C04Customer behavior monitoring" Or _
                w = "C04Incomplete Address" Or _
                w = "C04Fail ID expired date logic check" Or _
                w = "C05PAT testing - Fail PSB check" Or _
                w = "C05Hubei Province" Or _
                w = "C05Jiebei Ever30+" Or _
                w = "C05rewrite account" Or _
                w = "C04Fail KYC check" Or _
                w = "C05skip account" Then
            GoTo Next1
        Else
            MsgBox "第" & q & "行数据有问题,block reason code 和 reason remark不对"
            Range("A" & q).Select
            GoTo Issueexit
        End If
              
Next1:
        e = Len(Range("E" & q).Value)
        If e = "9" Then
            GoTo Next2
        Else
            MsgBox "第" & q & "行数据有问题,客户号长度不对"
            Range("A" & q).Select
            GoTo Issueexit
        End If

Next2:
        If Range("F" & q).Value = "AML Batch Screening Not Contactable" And Range("I" & q).Value = "" Then
            MsgBox "第" & q & "行数据有问题,I列缺少remark"
            Range("A" & q).Select
            GoTo Issueexit
        Else
            GoTo Next3
        End If
Next3:
        If Range("A" & q).Value = "" Then
            MsgBox "第" & q & "行数据有问题,A列缺少日期"
            Range("A" & q).Select
            GoTo Issueexit
        Else
            GoTo Next4
        End If
        

Next4: q = q + 1
    
    Loop



'=====
Issueexit: Application.ScreenUpdating = True
            Application.Calculation = xlCalculationAutomatic '自动重算

'********************************************************************************************************************

'Determine how many seconds code took to run
  SecondsElapsed = Round(Timer - StartTime, 2)

'Notify user in seconds
  MsgBox "验证时间共计 " & SecondsElapsed & " seconds", vbInformation
    
Range("A" & q).Select

End Sub




EXL 202105 Autobackup - DLP

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    
    Application.ScreenUpdating = False
    
    Dim SavePath As String, myName As String, ext As String, user As String, T As String, File As String
    
    SavePath = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Report center\CNDLP Blacklist backup\"
    myName = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".") - 1)) '文件名
    ext = Right(ThisWorkbook.Name, Len(ThisWorkbook.Name) - InStrRev(ThisWorkbook.Name, ".")) '文件后缀
    user = Environ("username") '文件编辑用户名
    T = Format(Now, "yyyymmdd-hhmmss")
    File = SavePath & myName & " " & T & "-" & user & "." & ext
        
    ActiveSheet.Copy
        ActiveWorkbook.SaveAs Filename:= _
            SavePath & myName & " " & T & "-" & user & ".xlsx" _
            , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        
        Columns("C:D").ClearContents
        ActiveWorkbook.Save
        ActiveWindow.Close
    Application.ScreenUpdating = True
    
End Sub

Private Sub Workbook_Open()

End Sub

EXL 202105 Personal

Sub InputPath(w As String)

w = InputBox("路径")

    If w = "DL" Or w = "dl" Or w = "" Then
        w = "\\shavnasgcg0001\bg52134$\Downloads"
    ElseIf w = "IP" Or w = "ip" Then
        w = "\\shavnasgcg0001\bg52134$\1-Irene\Citikyc & Project\0-Mail communication"
    ElseIf w = "IL" Or w = "il" Then
        w = "\\shavnasgcg0001\bg52134$\1-Irene\Citikyc & Project\0-Other Log"
    ElseIf w = "PP" Or w = "pp" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\1-Policy & Other process"
    ElseIf w = "PO" Or w = "po" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\Others"
    ElseIf w = "TT" Or w = "tt" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\Temp"

    'CDD & Screening
    ElseIf w = "PSCREENING" Or w = "pscreening" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\BAU name screening"
    ElseIf w = "PCDD" Or w = "pcdd" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\BAU CDD or KYC refresh"

    'Project
    ElseIf w = "UAT" Or w = "uat" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\CBSU BAU Projects\2021 Q2 AML CDD CR testing"
    ElseIf w = "FRD" Or w = "frd" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\CBSU BAU Projects\2021 Q2 AML CDD CR testing\1-BRD FRD"
    ElseIf w = "screening" Or w = "SCREENING" Then
        w = "I:\1-Irene\Citikyc & Project\6-OPPM\2021 Q2 CSAW C Screening"

    'Temp
    ElseIf w = "CSI" Or w = "csi" Then
        w = "X:\CBSU\MCA-AML\2021\Q2\CBSU Testing\202104 CitiScreening Product Issue - No hit"


    'MCA
    ElseIf w = "mca" Or w = "MCA" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\MCA-AML\2021\Q1\CBSU Testing result"

    End If

End Sub

Sub A_另存当前文件()

Application.ScreenUpdating = False

Dim w As String, CK2 As String, mypath As String, myfilename As String

Call InputPath(w)

        mypath = w & "\"
        'On Error Resume Next
        'VBA.MkDir (mypath)

    CK2 = MsgBox("用当前文件名?", vbYesNo)
        If CK2 = 6 Then
            myfilename = ActiveWorkbook.Name
'            MsgBox mypath & myfilename
            ActiveWorkbook.SaveAs Filename:= _
            mypath & myfilename, _
            FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        Else
            myfilename = InputBox("输入文件名") & ".xlsx"
'            MsgBox mypath & myfilename
            ActiveWorkbook.SaveAs Filename:= _
            mypath & myfilename, _
            FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        End If
    
    Dim obj As Object
    Set obj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    obj.SetText mypath & myfilename
    obj.PutInClipboard
    Set obj = Nothing

Application.ScreenUpdating = True

        
End Sub

Sub A_当前sheet保存()
Application.ScreenUpdating = False
ActiveWorkbook.Save

'Dim sht As Worksheet
'sht = ActiveSheet
    ActiveSheet.Copy
     ActiveWorkbook.SaveAs Filename:= _
        "\\shavnasgcg0001\bg52134$\Downloads\" & ActiveSheet.Name & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWindow.Close

Dim obj As Object
    Set obj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    obj.SetText "\\shavnasgcg0001\bg52134$\Downloads\" & ActiveSheet.Name & ".xlsx"
    obj.PutInClipboard
    Set obj = Nothing
  


Application.ScreenUpdating = True
End Sub

Sub A_打开当前文件夹()

Shell "explorer.exe " & ActiveWorkbook.Path, vbMaximizedFocus

End Sub

Sub A_创建文件夹()
Dim myfilename As String, Filename As String
    
mypath = InputBox("文件夹地址") & "/"
Filename = InputBox("新文件夹名字")


    On Error Resume Next
    VBA.MkDir (mypath & Filename)
        
End Sub

Sub B_保护只读()

ActiveWorkbook.SaveAs WriteResPassword:="Citi1234", ReadOnlyRecommended:=False
ActiveWorkbook.Save

End Sub

Sub B_保护打开()

ActiveWorkbook.SaveAs Password:="Citi2020", ReadOnlyRecommended:=False
ActiveWorkbook.Save

End Sub

Sub B_目录()

    Sheets(1).Select
        Dim wt As Worksheet
        Sheets.Add.Name = "目录"
        Set wt = Worksheets("目录")
    
    Dim sht As Worksheet, irow As Integer
    irow = 2
    For Each sht In Worksheets
        wt.Cells(irow, "A").Value = irow - 1
        wt.Hyperlinks.Add Anchor:=wt.Cells(irow, "B"), Address:="", SubAddress:="'" & sht.Name & "'!A1", TextToDisplay:=sht.Name
        irow = irow + 1

    Next

End Sub

Sub C_功能_添加超链接()

Dim q As Long, w As String, mypath As String, myfilename As String, Thisyear As String
    
q = 2

Do While Range("A" & q).Value <> blank
    w = "I:\1-Irene\BAU\1-CDD reference checker\" & Range("B" & q).Value
    
    On Error Resume Next
    VBA.MkDir (w)
    
    ActiveSheet.Hyperlinks.Add Anchor:=Range("A" & q), Address:=w
    
    q = q + 1
Loop

'MsgBox w

    
End Sub

Sub C_功能_8位数字变日期格式()

Dim q As Long, w As String, year As String, month As String, day As String
    
q = 2

Do While Range("A" & q).Value <> blank
    
    w = Range("A" & q).Value
    year = Left(w, 4)
    month = Mid(w, 5, 2)
    day = Right(w, 2)
    
    year = year & "/" & month & "/" & day
    Range("B" & q).Value = year
    
    q = q + 1
Loop
    
End Sub

Sub D_MCA_SMP()

    Columns("A:A").Select
    Selection.EntireColumn.Hidden = True
    Columns("D:H").Select
    Selection.EntireColumn.Hidden = True
    Columns("K:K").Select
    Selection.EntireColumn.Hidden = True
    Columns("M:O").Select
    Selection.EntireColumn.Hidden = True
    Columns("Q:U").Select
    Selection.EntireColumn.Hidden = True
    Columns("W:X").Select
    Selection.EntireColumn.Hidden = True
    Columns("Z:AN").Select
    Selection.EntireColumn.Hidden = True
    Columns("AP:AQ").Select
    Selection.EntireColumn.Hidden = True
    Columns("AS:BE").Select
    Selection.EntireColumn.Hidden = True
    Columns("BG:BH").Select
    Selection.EntireColumn.Hidden = True
    Columns("BJ:CE").Select
    Selection.EntireColumn.Hidden = True
    Range("B1").Select
    Columns("B:B").EntireColumn.AutoFit
    Columns("B:B").ColumnWidth = 37.56
    Range("I1:J1").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("P1").Select
    With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
End Sub


Sub D_画文本框()

    ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 117, 35.4, 173.4, _
        72.6).Select
    Selection.ShapeRange.ShapeStyle = msoShapeStylePreset3
    Selection.ShapeRange.Fill.Visible = msoFalse
    With Selection.ShapeRange.Line
        .Visible = msoTrue
        .Weight = 4.5
    End With
    
    'Selection.Delete

End Sub



EXL 202105 Work File

Sub A_打开当前文件夹()

Shell "explorer.exe " & ActiveWorkbook.Path, vbMaximizedFocus

End Sub

Sub A_另存当前文件()

Application.ScreenUpdating = False

Dim CK As String, CK2 As String, mypath As String, myfilename As String

    CK = MsgBox("保存到Download?", vbYesNo)
        If CK = 6 Then
            mypath = "\\shavnasgcg0001\bg52134$\Downloads\"
        Else
            mypath = InputBox("文件路径") & "\"
    '        On Error Resume Next
    '        VBA.MkDir (mypath)
        End If
    CK2 = MsgBox("用当前文件名?", vbYesNo)
        If CK2 = 6 Then
            myfilename = ActiveWorkbook.Name
'            MsgBox mypath & myfilename
            ActiveWorkbook.SaveAs Filename:= _
            mypath & myfilename, _
            FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        Else
            myfilename = InputBox("输入文件名") & ".xlsx"
'            MsgBox mypath & myfilename
            ActiveWorkbook.SaveAs Filename:= _
            mypath & myfilename, _
            FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        End If

Application.ScreenUpdating = True

        
End Sub

Sub A_当前sheet保存()
Application.ScreenUpdating = False
ActiveWorkbook.Save

'Dim sht As Worksheet
'sht = ActiveSheet
    ActiveSheet.Copy
     ActiveWorkbook.SaveAs Filename:= _
        "\\shavnasgcg0001\bg52134$\Downloads\" & ActiveSheet.Name & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWindow.Close


Application.ScreenUpdating = True
End Sub


Sub A_创建文件夹()
Dim myfilename As String, Filename As String
    
mypath = InputBox("文件夹地址") & "/"
Filename = InputBox("新文件夹名字")


    On Error Resume Next
    VBA.MkDir (mypath & Filename)

    
        
End Sub


Sub B_目录()

    Sheets(1).Select
        Dim wt As Worksheet
        Sheets.Add.Name = "目录"
        Set wt = Worksheets("目录")
    
    Dim sht As Worksheet, irow As Integer
    irow = 2
    For Each sht In Worksheets
        wt.Cells(irow, "A").Value = irow - 1
        wt.Hyperlinks.Add Anchor:=wt.Cells(irow, "B"), Address:="", SubAddress:="'" & sht.Name & "'!A1", TextToDisplay:=sht.Name
        irow = irow + 1

    Next

End Sub

Sub A_添加超链接()

Dim q As Long, w As String, mypath As String, myfilename As String, Thisyear As String
    
q = 2

Do While Range("A" & q).Value <> blank
    'w = Range("B" & q).Value
    w = "I:\1-Irene\BAU\1-CDD reference checker\" & Range("B" & q).Value
    
    On Error Resume Next
    VBA.MkDir (w)
    'MsgBox w
    
    ActiveSheet.Hyperlinks.Add Anchor:=Range("A" & q), Address:=w
    
    q = q + 1
Loop

'MsgBox w

    
End Sub


Outlook 202105 Personal

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Option Explicit


Private Sub InputPatch(w As String)

w = InputBox("路径")

    If w = "DL" Or w = "dl" Or w = "" Then
        w = "\\shavnasgcg0001\bg52134$\Downloads"
    ElseIf w = "IP" Or w = "ip" Then
        w = "\\shavnasgcg0001\bg52134$\1-Irene\Citikyc & Project\0-Mail communication"
    ElseIf w = "IL" Or w = "il" Then
        w = "\\shavnasgcg0001\bg52134$\1-Irene\Citikyc & Project\0-Other Log"
    ElseIf w = "PP" Or w = "pp" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\1-Policy & Other process"
    ElseIf w = "PO" Or w = "po" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\Others"
    ElseIf w = "TT" Or w = "tt" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\Temp"

    'CDD & Screening
    ElseIf w = "PSCREENING" Or w = "pscreening" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\BAU name screening"
    ElseIf w = "PCDD" Or w = "pcdd" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\BAU CDD or KYC refresh"

    'Project
    ElseIf w = "UAT" Or w = "uat" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\CBSU BAU Projects\2021 Q2 AML CDD CR testing"
    ElseIf w = "FRD" Or w = "frd" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\CBSU BAU Projects\2021 Q2 AML CDD CR testing\1-BRD FRD"
    ElseIf w = "screening" Or w = "SCREENING" Then
        w = "I:\1-Irene\Citikyc & Project\6-OPPM\2021 Q2 CSAW C Screening"

    'Temp
    ElseIf w = "CSI" Or w = "csi" Then
        w = "X:\CBSU\MCA-AML\2021\Q2\CBSU Testing\202104 CitiScreening Product Issue - No hit"


    'MCA
    ElseIf w = "mca" Or w = "MCA" Then
        w = "\\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\MCA-AML\2021\Q1\CBSU Testing result"

    End If
        'Download - DL - \\shavnasgcg0001\bg52134$\Downloads\
        'My Project-IP - \\shavnasgcg0001\bg52134$\1-Irene\Citikyc & Project\0-Mail communication\
        'My Log-IL - \\shavnasgcg0001\bg52134$\1-Irene\Citikyc & Project\0-Other Log\
        'Pub Policy-PP - \\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\1-Policy & Other process\
        'Pub Policy Others-PO - \\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\Others
        'Pub Temp-TT - \\canvnasgcg0001\GRP_GCBCN_CBORC\CBSU\Policy & Sharing\Temp


End Sub

Public Sub 邮箱保存到下载()

Dim oMail As Object
Dim objItem As Object
Dim sPath As String
Dim sFrom As String
Dim dtDate As Date
Dim sName As String
Dim obj As Object
Dim enviro As String

For Each oMail In ActiveExplorer.Selection
    sName = oMail.Subject
    dtDate = oMail.ReceivedTime
    sFrom = Left(oMail.Sender, 15)
    ReplaceCharsForFileName sName, ""
    
    sName = Format(dtDate, "yy_mm_dd_", vbUseSystemDayOfWeek, vbUseSystem) & Format(dtDate, "hhnn", _
        vbUseSystemDayOfWeek, vbUseSystem) & "_" & sFrom & "-" & sName & ".msg"
    sPath = "\\shavnasgcg0001\bg52134$\Downloads\"
        'sPath = "I:\1-Irene\Mail backup\1- BAU-CDD\201912\" '邮件保存路径
    Debug.Print sPath & sName
    
    oMail.SaveAs sPath & sName, olMSG
    
    'Sleep 4000
Next

        Set obj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        obj.SetText sPath & sName
        obj.PutInClipboard
        Set obj = Nothing

End Sub

Public Sub 邮箱保存指定路径()

Dim oMail As Object
Dim objItem As Object
Dim sPath As String
Dim sFrom As String
Dim dtDate As Date
Dim sName As String
Dim obj As Object
Dim enviro As String
Dim w As String

InputPatch w

For Each oMail In ActiveExplorer.Selection
    sName = oMail.Subject
    dtDate = oMail.ReceivedTime
    sFrom = Left(oMail.Sender, 15)
    ReplaceCharsForFileName sName, ""
    
    sName = Format(dtDate, "yy_mm_dd_", vbUseSystemDayOfWeek, vbUseSystem) & Format(dtDate, "hhnn", _
        vbUseSystemDayOfWeek, vbUseSystem) & "_" & sFrom & "-" & sName & ".msg"
    sPath = w & "\"
        'sPath = "I:\1-Irene\Mail backup\1- BAU-CDD\201912\" '邮件保存路径
    Debug.Print sPath & sName
    oMail.SaveAs sPath & sName, olMSG
    
    'Sleep 4000
Next
    
    Set obj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    obj.SetText sPath & sName
    obj.PutInClipboard
    Set obj = Nothing
  
End Sub
Public Sub 保存当前打开邮件()

Dim oMail As Object
Dim objItem As Object
Dim sPath As String
Dim sFrom As String
Dim dtDate As Date
Dim sName As String
Dim obj As Object
Dim enviro As String
Dim w As String

InputPatch w

Set oMail = ActiveInspector.CurrentItem
    sName = oMail.Subject
    dtDate = oMail.ReceivedTime
    sFrom = Left(oMail.Sender, 15)
    ReplaceCharsForFileName sName, ""
    
    sName = Format(dtDate, "yy_mm_dd_", vbUseSystemDayOfWeek, vbUseSystem) & Format(dtDate, "hhnn", _
        vbUseSystemDayOfWeek, vbUseSystem) & "_" & sFrom & "-" & sName & ".msg"
    sPath = w & "\"
        'sPath = "I:\1-Irene\Mail backup\1- BAU-CDD\201912\" '邮件保存路径
    Debug.Print sPath & sName
    oMail.SaveAs sPath & sName, olMSG

    
    Set obj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    obj.SetText sPath & sName
    obj.PutInClipboard
    Set obj = Nothing
  
End Sub
Sub 记录时间()
Dim StartTime As Double
Dim SecondsElapsed As Double
'Remember time when macro starts
  StartTime = Timer

'*****************************
    Dim oMail As Object
    Dim dtDate As Date
    Dim sName As String
    Dim sFrom As String

    For Each oMail In ActiveExplorer.Selection


        dtDate = oMail.ReceivedTime
        sName = oMail.Subject
        sFrom = Left(oMail.Sender, 15)
        ReplaceCharsForFileName sName, ""

       sName = Format(dtDate, "yy_mm_dd_", vbUseSystemDayOfWeek, vbUseSystem) & Format(dtDate, "hhnn", _
        vbUseSystemDayOfWeek, vbUseSystem) & "_" & sFrom & "-" & sName
        oMail.Subject = sName
        oMail.Save
    Next
    
'*****************************

'Determine how many seconds code took to run
  SecondsElapsed = Round(Timer - StartTime, 2)

'Notify user in seconds
  MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
End Sub

Sub 修改名字()
Dim StartTime As Double
Dim SecondsElapsed As Double
'Remember time when macro starts
  StartTime = Timer

'*****************************
    Dim oMail As Object
    Dim dtDate As Date
    Dim sName As String
    Dim sFrom As String

    For Each oMail In ActiveExplorer.Selection


        dtDate = oMail.ReceivedTime
        sName = oMail.Subject
        sFrom = Left(oMail.Sender, 15)
        sName = Format(dtDate, "yy_mm_dd_", vbUseSystemDayOfWeek, vbUseSystem) & Format(dtDate, "hhnn", _
        vbUseSystemDayOfWeek, vbUseSystem) & "_" & sFrom & "-" & sName
        
        ReplaceCharsForFileName sName, ""
        oMail.Subject = sName
        oMail.Save
    Next
    
'*****************************

'Determine how many seconds code took to run
  SecondsElapsed = Round(Timer - StartTime, 2)

'Notify user in seconds
  MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
End Sub

Private Sub ReplaceCharsForFileName(sName As String, sChr As String)

  sName = Replace(sName, "'", sChr)
  sName = Replace(sName, "*", sChr)
  sName = Replace(sName, "/", sChr)
  sName = Replace(sName, "\", sChr)
  sName = Replace(sName, ":", sChr)
  sName = Replace(sName, "?", sChr)
  sName = Replace(sName, Chr(34), sChr)
  sName = Replace(sName, "<", sChr)
  sName = Replace(sName, ">", sChr)
  sName = Replace(sName, "|", sChr)
  sName = Replace(sName, "!", sChr)
  sName = Replace(sName, ":", sChr)
  sName = Replace(sName, ":", sChr)
  sName = Replace(sName, "】", sChr)
  sName = Replace(sName, "【", sChr)
  sName = Replace(sName, "  ", sChr)
  sName = Replace(sName, ",", sChr)
  sName = Replace(sName, "(", sChr)
  
  If Len(sName) > 120 Then
    sName = Left(sName, 120)
  End If
  
End Sub


Public Sub 延迟发送SendDeferredMessage()
Dim objMsg As MailItem
Dim SendAt

Set objMsg = ActiveInspector.CurrentItem

'send at 8:24 AM. .25 = 6 AM, .50 = noon // (.25 = 6 AM, .50 = noon, .75 = 6 PM.)
    'MyDate contains the date for February 12, 1969.
    'MyDate = DateSerial(1969, 2, 12)    ' Return a date.
    'SendAt = DateSerial(Year(Now), Month(Now), Day(Now + 3)) + #9:00:00 AM#

SendAt = DateSerial(2021, 6, 1) + #9:00:00 AM#



  objMsg.DeferredDeliveryTime = SendAt

 'displays the message form
  objMsg.Display
  
  Set objMsg = Nothing

End Sub


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,014评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,796评论 3 386
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,484评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,830评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,946评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,114评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,182评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,927评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,369评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,678评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,832评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,533评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,166评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,885评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,128评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,659评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,738评论 2 351

推荐阅读更多精彩内容