View Full Version : [SOLVED:] Save a file triggered by Outlook Rule
colonials13
07-24-2015, 06:44 AM
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!
gmayor
07-25-2015, 01:06 AM
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.
colonials13
07-25-2015, 09:31 AM
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
gmayor
07-25-2015, 08:46 PM
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
colonials13
07-27-2015, 10:57 AM
Worked out great! just what I needed! Thanks for all the help!
skatonni
07-27-2015, 01:13 PM
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.