1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
Sub auto_open()
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Dim result As Boolean
If Sheets("Parms").Range("A1") = 1 Then
send_email
End If
End Sub
Sub send_email()
Dim result As Boolean
Cells.Select
Selection.ClearContents
Range("A1").Select
'ChDir "C:\Documents and Settings\admincot\Desktop"
Workbooks.OpenText Filename:="C:\DATA\Test\testexcel\Usage.txt", Origin:= _
xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _
, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:= _
False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Cells.Select
Selection.Copy
Windows("Classeur1.xls").Activate
ActiveSheet.Paste
Columns("E:E").Select
Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Application.CutCopyMode = False
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.NumberFormat = "0.00"
result = False
With ActiveSheet
For Each cell In .Range(Range("E65536").End(xlUp), Range("E5"))
If cell.Value > 99.5 Then
result = True
Exit For
End If
Next
End With
Rows("8:8").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Sort Key1:=Range("E8"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Selection.AutoFilter
Selection.AutoFilter Field:=5, Criteria1:=">99,5", Operator:=xlAnd
Range("A6").Select
Selection.TextToColumns Destination:=Range("A6"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), _
TrailingMinusNumbers:=True
Rows("4:4").Select
Selection.Delete Shift:=xlUp
Rows("1:2").Select
Range("A2").Activate
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Font.Bold = True
Range("A1:E1").Select
With Selection
.HorizontalAlignment = xlCenterAcrossSelection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.FormulaR1C1 = "Quotas on EUFRHQFS01WP"
Rows("3:3").Select
Selection.Font.Bold = True
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
Columns("E:E").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="99,5", Formula2:="99,9"
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 46
End With
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="99,9"
With Selection.FormatConditions(2).Font
.Bold = True
.Italic = False
.ColorIndex = 3
End With
Range("E3").Select
Selection.Font.ColorIndex = 0
With Selection.Font
.Name = "Arial"
.FontStyle = "Gras"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
Columns("E:E").Select
Selection.TextToColumns Destination:=Range("E1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Range("A2").Select
ActiveWorkbook.Save
On Error Resume Next
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim dest As String
Dim monTab() As String
Dim newname As String
If result Then
Msg = "Usage > 99,5. Do you want to Send the Mail ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "MsgBox Send" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt) 'METTRE EN COMMENTAIRE
If Response = vbNo Then ' User chose No 'METTRE EN COMMENTAIRE
Exit Sub
End If 'METTRE EN COMMENTAIRE
Else
Exit Sub
End If
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GetDatabase("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
MailDoc.Subject = "Envoi Automatique Alerte Quota FS01"
MailDoc.body = "Alerte de Quota sur FS01"
MailDoc.SAVEMESSAGEONSEND = saveit
Sheets("Parms").Range("A1") = 0
newname = "C:\Quota Alerte Mail.xls"
ThisWorkbook.SaveCopyAs Filename:=newname
Sheets("Parms").Range("A1") = 1
Attachment = newname
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
dest = Sheets("MACRO").Range("A1") & ", " & Sheets("MACRO").Range("A2")
monTab = Split(dest, ",")
MailDoc.Send 0, monTab()
MailDoc.PostedDate = Now()
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
Excel.Application.Quit
Application.DisplayAlerts = False
End Sub |
Partager