Code to create fldr for saved O2K message graphics if it isn't already there?

S

StargateFan

I've not had any luck with this; I've been told about something called
FileSystemObject, but that term is Greek to me. I of course looked in
the help file and tried to understand the process but no luck.
Nothing has worked. The code below comes from a website that was
recommended in one of these Outlook ngs and it allows us to save
embedded graphics in messages. _I_ didn't create this. So if it
looks sophisticated, it's because the person coding it knows what
they're doing, it sure looks like. It does have one _serious_ flaw,
if the folder isn't present, the graphics aren't saved and we aren't
warned of this fact either.

Any help with code would be greatly appreciated. Just a newbie here,
not even close to being a vb expert or anything though I've been able
to do a lot more on my own lately. Tx.

****************************************************************
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")

For Each objAttachment In colAttachments
objAttachment.SaveAsFile
("C:\WINDOWS\Desktop\OutlookEmbeddedGraphics\" &
objAttachment.FileName)
Next

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

End Sub
****************************************************************
 
K

Ken Slovak - [MVP - Outlook]

That code is incomplete. As you see it never uses the Shell object it
creates (plus it names it with a str prefix, which is used for strings and
not objects).

The documentation for the FileSystemObject is in the Windows Scripting Help
file.

Look at the code at
http://www.slovaktech.com/code_samples.htm#StripAttachments. That code uses
FileSystemObject to get the Temp file and save the attachments there using
the following function:

Private Function GetTempDir() As String
Const TemporaryFolder = 2

'Requires a project reference to "Scrrun.dll" (Windows Scripting)
Dim fso As Scripting.FileSystemObject
Dim tFolder As Scripting.Folder

On Error Resume Next

' Instantiate a WSH (Windows Scripting Host)
' FileSystemObject.
Set fso = CreateObject("Scripting.FileSystemObject")
' Get the Temp folder.
Set tFolder = fso.GetSpecialFolder(TemporaryFolder)

If Err Then
GetTempDir = ""
Else
GetTempDir = LCase(tFolder.Path)
' Add "\" to the rightmost part of the path to
' the Temp folder if necessary.
If Right$(GetTempDir, 1) <> "\" Then
GetTempDir = GetTempDir & "\"
End If
End If

Set fso = Nothing
Set tFolder = Nothing
End Function

FileSystemObject also has methods to see if a folder exists (FolderExists)
and to create a folder (CreateFolder).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top