Consulting

Results 1 to 6 of 6

Thread: Save a file triggered by Outlook Rule

  1. #1

    Save a file triggered by Outlook Rule

    Hi All,

    This is my first post so hope I explain this well.

    I'm trying to create code in Outlook to be triggered upon receiving a certain email; I'm having a hard time creating the code.

    What it needs to do, is go to a specific file path on a shared drive, Select the File named "Office Phone Directory List" and then save it to my desktop.

    Any help with this, would be awesome! Thanks!

  2. #2
    What is the file format of the File named "Office Phone Directory List"? In order to 'save it' you have to be able to 'open' it, so it helps to know what will open it, or will copying it suffice?
    I take it this file does not relate to the e-mail message other than as a trigger to make the save?
    What do you want to happen if the file already exists on your desktop?
    What is the address of the 'shared drive'? Is this a network location? If so, is it mapped to a Windows drive letter?
    You will need a rule to identify the message and run the macro.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Office Phone.... Word Document.
    Copying it to my desktop would suffice just as much.
    No the file does not relate to the email.... the email is a share point trigger. The file will already exists on my desktop so i just want it to overwrite it.


    So far, I have it to do an if statement, to check if the file exists, knowing that it does I just want it to save but cant seem to get that part. I was thinking of trying to just do a save as right after the If then, but that's where I'm stuck. The file name is where i want to save or copy to. and the the strPath is where the file is located.


    Sub PhoneList() '(item As Outlook.MailItem)


    Dim ObjFso As Object
    Dim strPath As String
    Dim CheckExists As Boolean
    Dim FileName As String




    'FileName = "C:\Users\T105739\Desktop"


    'file path
    strPath = "\\controller.alleghenycounty.us\DavWWWRoot\Employee Phone List\Office Phone Directory List.doc"
    Set ObjFso = CreateObject("Scripting.FileSystemObject")
    'deletes file
    CheckExists = ObjFso.FileExists(strPath)
    If CheckExists = True Then
    File.SaveAs Scripting.FileSystemObject
    'MsgBox ("The file exists")
    Else
    MsgBox ("The file does not exist")
    End If

  4. #4
    In that case

    Sub PhoneList(item As Outlook.MailItem)
    Dim ObjFso As Object
    Dim strPath As String
    Dim strFileName As String
        strFileName = "C:\Users\T105739\Desktop\Office Phone Directory List.doc"
        strPath = "\\controller.alleghenycounty.us\DavWWWRoot\Employee Phone List\Office Phone Directory List.doc"
        Set ObjFso = CreateObject("Scripting.FileSystemObject")
        If ObjFso.FileExists(strPath) = True Then
            MsgBox ("The file exists")
            ObjFso.CopyFile strPath, strFileName, True
        Else
            MsgBox "The file does not exist"
        End If
    lbl_Exit:
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    Worked out great! just what I needed! Thanks for all the help!

  6. #6
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    This is an alternative, not necessarily better.

    Private Sub PhoneList_ThroughOutlook(item As MailItem)
    
        ' Ignore the incoming item to be safe.
        
        Dim newItem As MailItem
        Dim Atmt As attachment
        Dim FileName As String
        
        Set newItem = CreateItem(olMailItem)
        
        newItem.Attachments.Add "H:\Test\Office Phone Directory List.doc"
        
        For Each Atmt In newItem.Attachments
            ' do not save images that may be in your signature
            If InStr(1, Atmt.FileName, "Office Phone Directory List") Then
            
                ' If not Citrix
                'FileName = Environ("USERPROFILE") & "\Desktop\" & Atmt.FileName
                
                ' If Citrix
                FileName = "V:\Users\" & Environ("USERNAME") & "\Desktop\" & Atmt.FileName
                
                Atmt.SaveAsFile FileName
                Exit For
                
            End If
        Next Atmt
        
        newItem.Close olDiscard
        Set Atmt = Nothing
        Set newItem = Nothing
            
    End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •