ContactEZ.net D. G. Schneider International Lions Club Volunteer Project

ContactEZ.net

Outlook Automation Launch Automated Message if a File is Located

See more discussions and posts about automation:

Help Launch Automated Message After Product Build

Simple automation - Assistant recherche

Sripts for Natural Language Translation

Command Line:
"C:\Program Files\Microsoft Office\Office\outlook.exe" /c ipm.note /m "dgschnei@ingr.xyz&subject=Testing Command Line %20subject&body=Hello%20 Dominique"

"C:\Program Files\Microsoft Office\Office\outlook.exe" /select outlook:FolderName See more information

ThisOutlooKSession:

Private Sub Application_Startup()

Dim StartHour
   StartHour = Hour(Now)
        If StartHour > 19 and StartHour < 24 Then
            Main 'start Main macro
       Else
' Do Something else...
       End If
End Sub

Rules Wizard
Outlook 2002 Visual Basic for Applications can be used in the Rules Wizard by using the "Run a Script" option.
For more information see How to create a script for the Rules Wizard in Outlook

For more information search Outlook Command-Line Switches in Microsoft Knowledge Base

1) Start Outlook

2) Select Tools > Macros > Macro (Alt-F8)

3) Enter a name for the new macro

4) Select Create then cut and paste the following code (note: use olByReference or olByValue).
Option Explicit

Dim KeepWaiting As Boolean
Public Sub Main()



Dim StartHour, Time2Pause, Start

Dim I As Integer



   If (MsgBox("Press Yes to start macro", 4)) = vbYes Then

        StartHour = Hour(Now)

        KeepWaiting = True

        I = 1

        Do While KeepWaiting = True

               If Hour(Now) >= StartHour + I Then

                 IsLogFileThere 'check every hour

                 I = I + 1

               Else

                    Time2Pause = 30   ' Set pause duration.

                    Start = Timer   ' Set start time.

                    Do While Timer < Start + Time2Pause

                       DoEvents   ' Yield to other processes.

                    Loop

               End If

        Loop

        'MsgBox "Debug  Exit loop cause Keepwaiting = false"

    Else

        End

    End If

End Sub

Sub IsLogFileThere()



On Error GoTo ERR_Trap



    Dim ol As New Outlook.Application

    Dim ns As Outlook.NameSpace

    Dim newMail As Outlook.MailItem

    Dim MSg As String

    Dim FSO

    Dim ws



Set ws = CreateObject("WScript.Network")

ws.MapNetworkDrive "X:", "\\rel52\c$"

     

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FileExists("X:\GM\Logs\Release0.log") Then

    'Return a reference to the MAPI layer.

    Set ns = ol.GetNamespace("MAPI")

    

    'Create a new mail message item.

    Set newMail = ol.CreateItem(olMailItem)

    With newMail

        'Add the subject of the mail message.

        .Subject = "Testing automation Log and Report from builder"

        'Create some body text.

        MSg = "This is an automated message. " & Chr(10)

        MSg = MSg & "Product Build Finished - Successful!" & Chr(10)

        MSg = MSg & "Please read attached log file and correct any error." & Chr(10) & Chr(10)

        MSg = MSg & "For more information and assistance, read the CM Help file: " & Chr(10)

        MSg = MSg & "http://theserver/thefolder/ISO_9000_CM_Help.chm" & Chr(10)

        .Body = MSg



        'Add a recipient and test to make sure that the

        'address is valid using the Resolve method.

        With .Recipients.Add("mylogin@contactez.net")

            .Type = olTo

            If Not .Resolve Then

                MsgBox "Unable to resolve address.", vbInformation

                Exit Sub

            End If

        End With



        'Attach a file as a link with an icon.

        With .Attachments.Add _

            ("X:\Folder1\Folder2\EndofBuild.log", olByReference)

            .DisplayName = "Log Report from Huntsville Product Builder"

        End With



        'Send the mail message.

        .Send

        KeepWaiting = False

    End With



    'Release memory.

    Set ol = Nothing

    Set ns = Nothing

    Set newMail = Nothing

Else

    'MsgBox "Debug - Log not found. Wait Until Found."

    KeepWaiting = True

End If

    

ws.RemoveNetworkDrive "X:", True



ERR_Trap:

Select Case Err

     Case 0:

     Case Else:

      MsgBox "Error in Outlook VBaProject Macro into Function IsLogFileThere " & Err 

     End

 End Select

End Sub

For more information go to Google Groups Outlook Program VBA

About Dominique Gérard Schneider since 1995
Participation on Google
ContactEZ.net on YouTube

Tek-Tips Forums dgschnei
Listed since 1996 ixquick
Community Services

platform sdk dgschnei
Cooperation
About Me

Return Home - Index