J
JoBo
I have used the following sample code obtained from the
net to automate the saving of specific attachments. This
code is triggered at start-up and does the job neatly
apart from the security message box, which, as I know the
origins of the text file is not really necessary. I would
also like to move the message to another folder after the
attachment has been saved and mark it as read, then open
and run an access database that would upload the saved
text file. I have tried setting the destination folder and
using Move to no avail. Any help or pointers would be much
appreciated.
Thanks Joe
Public Sub saverep()
Dim oApp As Application
Dim oNS As NameSpace
Dim oMessage As Object
Dim oAttachments As Outlook.Attachments
Dim NbrMsgs
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
NbrMsgs = 0
'Cycle through the messages
For Each oMessage In oFolder.Items
With oMessage
If .SenderName = "Jim Brown" Then
If oMessage.UnRead = True Then
NbrMsgs = NbrMsgs + 1
oMessage.Attachments.Item
(1).SaveAsFile "C:\Documents and Settings\Joe\My
Documents\Allstar Fuel Cards\FUELTR_27181908.txt"
End If
End If
End With
' Dim oaccessApp As access.Application
' Set oaccessApp = ("C:\Documents
and Settings\Joe\My Documents\fuel06b.mdb")
' docmd.runcommand.openform
("Import")
Next
End Sub
net to automate the saving of specific attachments. This
code is triggered at start-up and does the job neatly
apart from the security message box, which, as I know the
origins of the text file is not really necessary. I would
also like to move the message to another folder after the
attachment has been saved and mark it as read, then open
and run an access database that would upload the saved
text file. I have tried setting the destination folder and
using Move to no avail. Any help or pointers would be much
appreciated.
Thanks Joe
Public Sub saverep()
Dim oApp As Application
Dim oNS As NameSpace
Dim oMessage As Object
Dim oAttachments As Outlook.Attachments
Dim NbrMsgs
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
NbrMsgs = 0
'Cycle through the messages
For Each oMessage In oFolder.Items
With oMessage
If .SenderName = "Jim Brown" Then
If oMessage.UnRead = True Then
NbrMsgs = NbrMsgs + 1
oMessage.Attachments.Item
(1).SaveAsFile "C:\Documents and Settings\Joe\My
Documents\Allstar Fuel Cards\FUELTR_27181908.txt"
End If
End If
End With
' Dim oaccessApp As access.Application
' Set oaccessApp = ("C:\Documents
and Settings\Joe\My Documents\fuel06b.mdb")
' docmd.runcommand.openform
("Import")
Next
End Sub