View Single Post
  #5  
Old March 9th 07, 11:18 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 3,426
Default How to have Outlook create folder if folder is not present?

Sub SaveAttachment()
Dim objCurrentItem As Outlook.MailItem
Dim colAttachments As Outlook.Attachments
Dim objAttachment As Outlook.Attachment
Dim objFSO As Scripting.FileSystemObject
Dim strPath As String
Dim strFolder As String

Set objCurrentItem = Application.ActiveInspector.CurrentItem
Set colAttachments = objCurrentItem.Attachments
Set objFSO = CreateObject("Scripting.FileSystemObject")

strPath = "C:\Documents and Settings\Compaq_Administrator\Desktop\"
strFolder = "Outlook embedded graphics\"
strPath = strPath & strFolder

If Not(objFSO.FolderExists(strPath)) Then
objFSO.CreateFolder(strPath)
End If

For Each objAttachment In colAttachments
objAttachment.SaveAsFile (strPath & objAttachment.FileName)
Next

Set objAttachment = Nothing
Set colAttachments = Nothing
Set objCurrentItem = Nothing
Set objFSO = Nothing
End Sub

Make sure you have a reference set to IWshRuntimeLibrary
(C:\WINDOWS\system32\wshom.ocx) in Tools, References

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"StargateFanFromWork" wrote in message
...
snip
Hi, where would I put that in, pls? I didn't write the original script
above, btw [it's like Chinese to me, except that I'm able to figure out
where to change the folder path's name because that's rather obvious]),

but
I took the plunge and put the first line of code you mention in what

seemed
to me the most logical spot but I get this error:

"Compile error:

Expected: list separator or )"

You'll probably think it's stupid where I've put it in the code below but

I
have no idea where it would go, I'm sorry to say.


************************************************** **************************
********
Sub SaveAttachment()
Dim objCurrentItem As Outlook.MailItem
Dim colAttachments As Outlook.Attachments
Dim objAttachment As Outlook.Attachment

Set objCurrentItem = Application.ActiveInspector.CurrentItem
Set colAttachments = objCurrentItem.Attachments
Set strFolderpath = CreateObject("WScript.Shell")

FileSystemObject. FolderExists(FolderSpec As String) As Boolean

For Each objAttachment In colAttachments
objAttachment.SaveAsFile ("C:\Documents and
Settings\Compaq_Administrator\Desktop\Outlook embedded graphics\" &
objAttachment.FileName)
Next

Set objAttachment = Nothing
Set colAttachments = Nothing
Set objCurrentItem = Nothing

End Sub

************************************************** **************************
********

Thanks in advance for any further help.

Cheers. D


Though this is a vb group, perhaps it's not geared to helping with actual
scripts (?). If I'm in the wrong group, can someone direct me to a better
place, then, pls? This is an issue that I've been trying to resolve for
over a year but have not had luck.

Thanks, appreciate any help with this one. I honestly don't know what
I've
ever done wrong but I can't get it to work. And the script is incomplete.
It will absolutely not copy anything unless the folder is present and it's
a
big challenge to keep my desktop clean. Only need this folder when there
is
something embedded in the email that I need to save.

tia. D



Ads
 

Mortgage Calculator - Credit Card Consolidation - Free MP3 Download - Teaching the Trivium - Loans