Can you automat saving attachments and emails to a directory

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Open Inbox
Click on the new Email
Click on Marco which runs the following
Detaches any attachment in the Email to a set directory
Saves the text of the email to the same directory and a txt file or doc.

or could all the above be automated more by having the email do the above as
in arrived in the inbox as new mail. Set formated emails only for do this.
 
Neil1958 said:
Open Inbox
Click on the new Email
Click on Marco which runs the following
Detaches any attachment in the Email to a set directory
Saves the text of the email to the same directory and a txt file or
doc.

or could all the above be automated more by having the email do the
above as in arrived in the inbox as new mail. Set formated emails
only for do this.

Hi Neil,

To save the emails to a folder, just drag them across and copy or move
them. They will come across as MSG files which are fully functional
outlook items that can be opened and then forwarded or replied to just
like any other email in outlook.

Try this to save attachments (change the path to suit).

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Sub ExtractAttachments()

Dim MyItem As MailItem
Dim MyAtt As Attachment


Set SelectedItems = ActiveExplorer.Selection


For Each MyItem In SelectedItems

For Each MyAtt In MyItem.Attachments

MyAtt.SaveAsFile "D:\Temp\" & MyAtt.DisplayName

Next

Next

End Sub


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
Allan thanks for the quick response
You have answered part of the question and the Marco to detach the
attachments works great.

The saving of the actual email is still a question.
A bit of back ground
I receive an email in the same format each time and from the same source.
I copy the body of the email into an excel sheet. By using the copy and
paste function then excel automatically convert all the info into excel
format. The data is then converted into one line in a database automatically.

Is there a Marco to save the email? As you would do manually with "File" and
"Save" from the menu. Like the attachment save macro you sent me.

If not then what would be the Marco to copy the content of the email ready
to paste.
I use Ctrl/A and then Ctrl/C, from that I paste it into the excel clean up
file directly as text.

Then the macro can detach the attachments and I would have the email content
ready yo paste into excel. I already have the macro in excel which takes it
from the paste step through all the rest.

Thanks
Neil
 
Neil1958 said:
The saving of the actual email is still a question.
A bit of back ground
I receive an email in the same format each time and from the same
source.
I copy the body of the email into an excel sheet. By using the copy
and paste function then excel automatically convert all the info
into excel format.
The data is then converted into one line in a database automatically.

Is there a Marco to save the email? As you would do manually with
"File" and "Save" from the menu. Like the attachment save macro you
sent me.

If not then what would be the Marco to copy the content of the email
ready to paste.
I use Ctrl/A and then Ctrl/C, from that I paste it into the excel
clean up file directly as text.

Then the macro can detach the attachments and I would have the email
content ready yo paste into excel. I already have the macro in excel
which takes it from the paste step through all the rest.

Hi Neil,

You can select multiple emails, the do File - Save (chose a path /
name) and save them all as a single text file.

Does that do what you need, or are you really needing to have copied
the text in the emails to the clipboard?

If the latter, then I am not sure. You can copy text in VBA, but I
cannot get it to then paste to excel automagically.

Perhaps I am missing something really obvious here! Perhaps the excel
app needs to exist as an object in the outlook app and / or vice versa
for it to work? I am not up on that kind of thing.

Alan.
 
Allans thanks for pointing me the right direction.
Below is my final code
It runs this on all emails in the inbox:
Copies the body of the email to to seperate new excel fromat files in a set
directory.
Deattaches all attachment to a directory
Makes a file of the all emails file name which were converted. This file is
then used to bring all the above data back together in one data base.

Thanks for your help
Hvae a good day

Sub SetupALL()

' work on this one for excel.

Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim test As Integer

Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0
test = 0

Dim objItem As Object
Dim MyItem1 As Outlook.Inspector
Dim strPath As String
Dim ExcelApp As Object
Dim ExcelSheet As Object
Dim olApp As New Outlook.Application
Dim doc As Object
test = 1

'strPath = "D:\temp\_MyExcelDoc.xls"
'strPath = "G:\Alcatel\Outside_Plant_Records\DBYD\Temp\_MyExcelDoc.xls"
strPath = "M:\Alcatel\Outside_Plant_Records\DBYD\Temp\_MyExcelDoc.xls"
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelSheet = ExcelApp.Workbooks.Add

For Each Item In Inbox.Items
strname = Item.Subject

ExcelSheet.ActiveSheet.Cells(test, 1).Value = Mid(strname, 5, 7)
'Item.SaveAs "d:\temp\" & Mid(strname, 5, 7) & ".xls", olTXT
'Item.SaveAs "G:\Alcatel\Outside_Plant_Records\DBYD\Temp\" &
Mid(strname, 5, 7) & ".xls", olTXT
Item.SaveAs "M:\Alcatel\Outside_Plant_Records\DBYD\Temp\" & Mid(strname,
5, 7) & ".xls", olTXT
test = test + 1
i = i + 1

Next Item

ExcelSheet.SaveAs strPath
ExcelApp.Quit
Set ExcelApp = Nothing

For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
'FileName = "D:\temp\" & Atmt.FileName
'FileName = "G:\Alcatel\Outside_Plant_Records\DBYD\Notification\" &
Atmt.FileName
FileName = "M:\Alcatel\Outside_Plant_Records\DBYD\Notification\" &
Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item

End Sub
 
Neil1958 said:
Allans thanks for pointing me the right direction.
Below is my final code
It runs this on all emails in the inbox:
Copies the body of the email to to seperate new excel fromat files in
a set directory.
Deattaches all attachment to a directory
Makes a file of the all emails file name which were converted. This
file is then used to bring all the above data back together in one
data base.

Thanks for your help
Hvae a good day

Great! You are most welcome.

I am bookmarking this as something that might be useful in the future!

Alan.
 
I've been using a macro similar to the one Alan posted here a couple years
ago. I ran into some problems when the company migrated from XP to Vista.
The code is still digitally signed, but Outlook appears to be ignoring the
script in the rule that calls it. I've set break points in the code but none
of them seem to fire.
I know that the rule is running, because it's executing the move to specify
folder and mark as read features of it.

Any ideas why Outlook 2007 would be ignoring breakpoints or script code all
together?

-Keiran
 
Back
Top