IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Supprimer macro avant envoi fichier par Mail


Sujet :

Macros et VBA Excel

  1. #21
    Membre du Club
    Profil pro
    Inscrit en
    Août 2007
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 141
    Points : 40
    Points
    40
    Par défaut
    Oh la la, j'ai parlé trop vite....
    Le mail part quand-même si toutes les valeurs sont en dessous de 99,85 (j'ai modifié, je préfère que le mail parte uniquement si il y a des valeurs sup à 99,85)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    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:="\\eufrhqfs01wp\QUOTALOG\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("Alerte Quota.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
        Selection.NumberFormat = "0.00"
     
        result = False
            With ActiveSheet
                For Each cell In .Range(Range("E65536").End(xlUp), Range("E5"))
                    If cell.Value > 99.85 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
        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("6:6").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
        Range("E8").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.FormatConditions.Delete
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
            Formula1:="99,5", Formula2:="99,85"
        With Selection.FormatConditions(1).Font
            .Bold = True
            .Italic = False
            .ColorIndex = 46
        End With
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
            , Formula1:="99,85"
        With Selection.FormatConditions(2).Font
            .Bold = True
            .Italic = False
            .ColorIndex = 3
        End With
        Rows("8:8").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.AutoFilter
        Columns("E:E").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Range("A3:A4").Select
        Selection.Font.Bold = True
        Range("A1").Select
        Range("E8").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.TextToColumns Destination:=Range("E8"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
            Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
            :=Array(1, 1), TrailingMinusNumbers:=True
        Range("A8:E46").Sort Key1:=Range("E8"), Order1:=xlDescending, Header:= _
            xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortTextAsNumbers
     
            Range("A6:E6").Select
        Range("E6").Activate
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        Range("A1").Select
        Range("A1").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,85. 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 Supérieur à 99,85% sur FS01"
        MailDoc.body = "Alerte Quota Supérieur à 99,85% 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

  2. #22
    Membre émérite Avatar de Godzestla
    Homme Profil pro
    Chercheur de bonheur
    Inscrit en
    Août 2007
    Messages
    2 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chercheur de bonheur
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2007
    Messages : 2 392
    Points : 2 985
    Points
    2 985
    Par défaut
    Bonjour,
    dans ton fichier texte il y avait une valeur supérieure à 112 !!!

  3. #23
    Membre du Club
    Profil pro
    Inscrit en
    Août 2007
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 141
    Points : 40
    Points
    40
    Par défaut
    Salut,

    Dans le fichier .txt que je t'ai adressé, il y avait effectivement une valeur à 112.
    Depuis, les quotas ont évolués et il n'y a plus de valeurs sup à 99,85.
    Pour tester, j'ai modifié le fichier manuellement en indiquant que des valeurs en dessous de 99,85 et le mail part quand-même.

  4. #24
    Membre émérite Avatar de Godzestla
    Homme Profil pro
    Chercheur de bonheur
    Inscrit en
    Août 2007
    Messages
    2 392
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chercheur de bonheur
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2007
    Messages : 2 392
    Points : 2 985
    Points
    2 985
    Par défaut
    Re,
    le code ci-dessous ne convient plus :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
         'If result Then
            'Msg = "Usage > 99,85. 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
    Remplace-le par ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
         If not result Then                               'rien trouvé > limite
              Exit Sub
         End If

  5. #25
    Membre du Club
    Profil pro
    Inscrit en
    Août 2007
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 141
    Points : 40
    Points
    40
    Par défaut
    Salut !
    Merci ça fonctionne !!!
    Merci pour ton aide.

    @+

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. Envoi fichier par mail
    Par jijie dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 25/04/2011, 17h43
  2. Réponses: 6
    Dernier message: 04/11/2010, 09h56
  3. Réponses: 12
    Dernier message: 20/10/2010, 11h27
  4. Envoi fichier par mail
    Par CmzxNene dans le forum WinDev
    Réponses: 8
    Dernier message: 10/08/2010, 12h23
  5. Envoi fichier par mail à partir d'Access
    Par Adrien972 dans le forum VBA Access
    Réponses: 2
    Dernier message: 21/03/2009, 23h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo