Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. Option Explicit
  2. Private WithEvents Items As Outlook.Items
  3.  
  4. Private Sub Application_Startup()
  5. Dim olApp As Outlook.Application
  6. Dim objNS As Outlook.NameSpace
  7. Set olApp = Outlook.Application
  8. Set objNS = olApp.GetNamespace("MAPI")
  9. ' default local Inbox
  10. Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
  11. End Sub
  12.  
  13. Private Sub Items_ItemAdd(ByVal item As Object)
  14.  
  15. On Error GoTo ErrorHandler
  16. Dim Msg As Outlook.MailItem
  17. If TypeName(item) = "MailItem" Then
  18. Set Msg = item
  19. ' ******************
  20. ' do something here
  21. ' ******************
  22.  
  23. End If
  24. ProgramExit:
  25. Exit Sub
  26. ErrorHandler:
  27. MsgBox Err.Number & " - " & Err.Description
  28. Resume ProgramExit
  29. End Sub
  30.  
  31. Private Sub Application_NewMail()
  32. 'MsgBox "Íîâîå ïèñüìî "
  33. Call ZNO_ZMMDOC_CRE
  34. End Sub
  35.  
  36. Public Sub ZNO_ZMMDOC_CRE()
  37. Dim DoW As String 'Äàòà íà÷àëà ðàáîò
  38. Dim lastrow As Long 'ïåðåìåííàÿ ïîèñêà ïîñëåäíåé ñòðîêè â Excel
  39. Dim myArray As Variant
  40. Dim i As Long
  41.  
  42. Dim olItem As Outlook.MailItem 'ïåðåìåííàÿ, îïðåäåëÿþùàÿ ïèñüìî
  43. Dim sText As String 'ìàññèâ äàííûõ äëÿ ïîèñêà ñîîòâåòñòâèé ðåãåêñïîâ
  44. Dim Excel As Object
  45. Dim ExcelBook As Object
  46.  
  47. Set ZNOnumber = CreateObject("VBScript.RegExp")
  48. ZNOnumber.Pattern = "(SR-[1-9]{7})"
  49.  
  50. Set olItem = ActiveExplorer.Selection.item(1)
  51.  
  52. sText = olItem.Body
  53. On Error Resume Next
  54. DoW = CStr(Year(Now))
  55. Set Excel = GetObject(, "Excel.Application")
  56.  
  57. 'MsgBox ZNOnumber.Test(TempStr)
  58.  
  59.  
  60.  
  61.  
  62. If Err.Number <> 0 Then
  63. If olItem.SenderName = "SDesk" Then
  64. myArray = Split(olItem.Body, Chr(13) & Chr(10))
  65.  
  66. If UBound(myArray) > -1 Then
  67. lastrow = worksheet.Cells(worksheet.Rows.Count, 1).End(xlUp).Row + 1
  68. For i = 0 To UBound(myArray)
  69. 'MsgBox myArray(i)
  70. If InStr(Left(myArray(i), 10), "Ïîëó÷àòåëü") > 0 Then
  71. If InStr(myArray(i), "Иванов") Then
  72. MsgBox "Íàø êëèåíò", vbApplicationModal, "ÇÍÎ"
  73. 'worksheet.Cells(i, 1).Value = myArray(i)
  74. Else
  75. Exit For
  76. End If
  77.  
  78. ElseIf InStr(Left(myArray(i), 7), "??????:") > 0 Then
  79. 'worksheet.Cells(lastrow, 2).Value = myArray(i)
  80. ElseIf InStr(Left(myArray(i), 11), "????/?????:") > 0 Then
  81. 'worksheet.Cells(lastrow, 3).Value = myArray(i)
  82. End If
  83. Next i
  84. End If
  85. End If
  86.  
  87. If InStr(olItem.SenderName, "Êîðñàêîâ Àëåêñåé Ñåðãååâè÷") Then
  88. 'MsgBox olItem.Body
  89. End If
  90.  
  91.  
  92. 'MsgBox Err.Description
  93. 'Set Excel = CreateObject("Excel.Application")
  94. 'Set xlBook = Excel.Workbooks.Add
  95. 'Set worksheet = Excel.Worksheets(1)
  96. 'Excel.Visible = True
  97.  
  98.  
  99.  
  100.  
  101. 'oBook.SaveAs ExcelBook
  102. Else
  103.  
  104. End If
  105. On Error GoTo 0
  106.  
  107.  
  108. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement