A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Saving attachements w/ names from a .xls file...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 23rd 07, 11:12 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 22
Default Saving attachements w/ names from a .xls file...

Here's what I am looking to do:

We have users that get multiple emails per day, from the same source,
always with an attachement. I'm looking to automate the open/save as/
save of the attached files, and have the file names stored in an Excel
spreadsheet. The users will update the sheet throughout the day, each
cell from A1 going down (A2, A3, etc) will have the next attachements
filename. This could also be done in a .txt file, but I'd prefer to
use Excel.

Anyway, here's my code so far (found/modified off a link from this
group):

Sub SaveAttachments()

'Declaration
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOrt As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection

'Ask for destination folder
myOrt = InputBox("Destination", "Save Attachments", "W:\test\")

On Error Resume Next

'work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection

'for all items do...
For Each myItem In myOlSel

'point on attachments
Set myAttachments = myItem.Attachments

'if there are some...
If myAttachments.Count 0 Then


'for all attachments do...
For i = 1 To myAttachments.Count


'save them to destination
myAttachments(i).SaveAsFile myOrt & _
myAttachments(i).DisplayName


Next i

End If

Next

'free variables
Set myItems = Nothing
Set myItem = Nothing
Set myAttachments = Nothing
Set myAttachment = Nothing
Set myOlApp = Nothing
Set myOlExp = Nothing
Set myOlSel = Nothing

End Sub

I'm assuming the section:

myAttachments(i).SaveAsFile myOrt & _
myAttachments(i).DisplayName

is where I want it to point at a spreadsheet prior to the save for the
filname, but I'm stuck on how to get it to do that and cycle down the
cells for the next name.

Any advice or support is as always, greatly appreciated.

Ads
  #2  
Old August 24th 07, 04:40 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 22
Default Saving attachements w/ names from a .xls file...

Alright, disregard the above for now (although I am curious for my own
personal reasons). I talked with my project manager and this is how
she wants it setup:

The email with the attachment comes in and a Rule executes the
following VB script:

Sub Test()

'Declaration
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOrt As String
Dim myFin As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection

'Ask for destination folder
myOrt = "W:\"

On Error Resume Next

'work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection

'for all items do...
For Each myItem In myOlSel

'point on attachments
Set myAttachments = myItem.Attachments

'if there are some...
If myAttachments.Count 0 Then


'for all attachments do...
For i = 1 To myAttachments.Count

'Ask for destination folder
myFin = InputBox("Please type a filename below:", "Saving
recording...", "")

'save them to destination
myAttachments(i).SaveAsFile myOrt & _
myFin

Next i
End If
Next
End Sub

My problem isnt so much of a VB script, the script works (although I'd
love to know the answer to my first question), but how to get
Outlook's Rules to execute a macro. I dont see any option for it
anywhere. Google's only pointing me to something called VB for
Applications..? Is that what its going to take?

The enviornment will be:

HP Thin Client w/
Windows 2003 Service Pack 2 w/
Microsoft Office 2003

Thanks as always!

  #3  
Old August 24th 07, 01:55 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Saving attachements w/ names from a .xls file...

An Outlook macro is always created using the Outlook VBA project. VBA stands
for Visual Basic for Applications. Any macro, whether it's being executed
independently or by a rule is always written using VBA code.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


wrote in message
ups.com...
Alright, disregard the above for now (although I am curious for my own
personal reasons). I talked with my project manager and this is how
she wants it setup:

The email with the attachment comes in and a Rule executes the
following VB script:

Sub Test()

'Declaration
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOrt As String
Dim myFin As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection

'Ask for destination folder
myOrt = "W:\"

On Error Resume Next

'work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection

'for all items do...
For Each myItem In myOlSel

'point on attachments
Set myAttachments = myItem.Attachments

'if there are some...
If myAttachments.Count 0 Then


'for all attachments do...
For i = 1 To myAttachments.Count

'Ask for destination folder
myFin = InputBox("Please type a filename below:", "Saving
recording...", "")

'save them to destination
myAttachments(i).SaveAsFile myOrt & _
myFin

Next i
End If
Next
End Sub

My problem isnt so much of a VB script, the script works (although I'd
love to know the answer to my first question), but how to get
Outlook's Rules to execute a macro. I dont see any option for it
anywhere. Google's only pointing me to something called VB for
Applications..? Is that what its going to take?

The enviornment will be:

HP Thin Client w/
Windows 2003 Service Pack 2 w/
Microsoft Office 2003

Thanks as always!


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I stop Outlook from saving names of people I send email to Dave Outlook - Using Contacts 1 June 15th 07 09:22 PM
File names do not appear when trying to export to any file type except .pst [email protected] Outlook - General Queries 8 December 25th 06 12:29 PM
Saving an email in .txt file Maggie Helton Outlook and VBA 1 August 23rd 06 05:54 AM
VCS file not saving formatting mocco02 Outlook - Calandaring 1 August 17th 06 11:17 AM
Saving emails as an HTML file Garret Swayne Outlook - General Queries 3 August 14th 06 02:39 PM


All times are GMT +1. The time now is 12:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.