What to add to this given code to have fldr created if fldr not present??

S

StargateFan

I just don't know how to fix this.

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. It has one _serious_ flaw, if the folder isn't present, the
graphics aren't saved and we aren't warned of this fact so it's
sometimes after I've deleted the msgs that I realize this fact (and,
yes, I keep clearing out my desktop and keep forgetting to re-create
the folder <sigh>).

Pls help.

Thanks.

****************************************************************
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
****************************************************************
 
M

Michael Bauer

Hi,

you could use the FileSystemObject instead of WScript.Shell. For that
please add a reference via Extras/References on "Microsoft Scripting
Runtime" to your project.

The FileSystemObject offers functions to check whether a folder exists
and lets create you the folder.
 
S

StargateFan

Hi,

you could use the FileSystemObject instead of WScript.Shell. For that
please add a reference via Extras/References on "Microsoft Scripting
Runtime" to your project.

Thanks but does anyone have the code for that? I've made modest
strides in modifying code given to me but don't know what you're
talking about yet.
 
M

Michael Bauer

Please just add the reference as I mentioned, then open the Object
Browser and watch the functions´ descriptions. Both,
FileSystemObject.FolderExists and FileSystemObject.CreateFolder, are
really self-explanatory.
 
S

StargateFan

Please just add the reference as I mentioned, then open the Object
Browser and watch the functions´ descriptions. Both,
FileSystemObject.FolderExists and FileSystemObject.CreateFolder, are
really self-explanatory.

Gee, I'm so glad you think so <sigh>.

Giving up again for now.

Sheesh, I just needed to add a line to create the folder if it isn't
there. It must be way more difficult since all these months later,
there are just hints about it and no code has been put forth. Makes
one wonder. As I've mentioned elsewhere, I've figured out how to do
the exact same thing in an AutoIt case and also in a Batch file
scenario, I just can't seem to get it to work in vba, a horribly more
complicated language.

Again, will have to live with the original code as is for now. I
can't afford a course to learn vba and all the stuff in the help is
better than nothing, but it's so complicated. Thanks anyway.
 
M

Michael Bauer

You better should have spent your time in reading the help instead of
creating this post. I´m quite sure, you didn´t.

The magic lines are:

Dim oFso as Scripting.FileSystemObject
set oFso = new Scripting.FileSystemObject
If not oFso.FolderExists(YourFolder) then
oFso.CreateFolder YourFolder
Endif
 
S

StargateFan

You better should have spent your time in reading the help instead of
creating this post. I´m quite sure, you didn´t.

You know something, this was a really offensive line. Of course I
read the help file back then and again this time around. I couldn't
make heads or tails of it. Why are the Outlook groups sometimes the
most condescending of all the MS groups? I've come back to try to
resolve this issue again now all these months later. I've gotten a
lot of fabulous help in the MS Access groups and the Excel ones re vb
so hoping that the little bit of extra knowledge would help with this.
But it's not so far. O2K vb code is different from A2K which is
different from XL2K code said:
The magic lines are:

Dim oFso as Scripting.FileSystemObject
set oFso = new Scripting.FileSystemObject
If not oFso.FolderExists(YourFolder) then
oFso.CreateFolder YourFolder
Endif

I never did get this to work and I tried again and it doesn't work
still. All that happened was that I walked away feeling very stupid
back then. Not much different this time around either. The Excel and
Access groups don't treat me as stupid. Why the different mentality,
I've always wondered.

"Best regards"? Wow.




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

All that is needed is for the above to look for the
"OutlookEmbeddedGraphics" folder and, if not there, to create it.
Michael Bauer - MVP Outlook

See? What in heck is the object browser?

Not to a newbie they aren't.

[snip]
 
K

Ken Slovak - [MVP - Outlook]

Any errors? Are you stepping the code to check?

It should work, I use code like that all the time. One thing to make sure of
is that a final backslash is added to the folder path you want to check. Are
you doing that?




StargateFan said:
You better should have spent your time in reading the help instead of
creating this post. I´m quite sure, you didn´t.

You know something, this was a really offensive line. Of course I
read the help file back then and again this time around. I couldn't
make heads or tails of it. Why are the Outlook groups sometimes the
most condescending of all the MS groups? I've come back to try to
resolve this issue again now all these months later. I've gotten a
lot of fabulous help in the MS Access groups and the Excel ones re vb
so hoping that the little bit of extra knowledge would help with this.
But it's not so far. O2K vb code is different from A2K which is
different from XL2K code said:
The magic lines are:

Dim oFso as Scripting.FileSystemObject
set oFso = new Scripting.FileSystemObject
If not oFso.FolderExists(YourFolder) then
oFso.CreateFolder YourFolder
Endif

I never did get this to work and I tried again and it doesn't work
still. All that happened was that I walked away feeling very stupid
back then. Not much different this time around either. The Excel and
Access groups don't treat me as stupid. Why the different mentality,
I've always wondered.

"Best regards"? Wow.




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

All that is needed is for the above to look for the
"OutlookEmbeddedGraphics" folder and, if not there, to create it.
Michael Bauer - MVP Outlook

See? What in heck is the object browser?

Not to a newbie they aren't.

[snip]
 
S

StargateFan

Any errors? Are you stepping the code to check?

"Stepping the code", what does this mean, pls?
It should work, I use code like that all the time. One thing to make sure of
is that a final backslash is added to the folder path you want to check. Are
you doing that?

Yes, that part I am doing. However, I'm guessing it's where this code
is going that perhaps is part of the problem. <sigh> I've tried
everything so far that I can find. I'm just a dumb newbie, however,
when it comes to vb <g>, so I'm obviously doing something wrong. I'll
google again over the weekend in the archives to see if I can find
_any_ example code close enough to this and correctly placed so that I
can see what I'm supposed to do exactly.

(And whenever I see that "dim" code anywhere, it's how I feel some
days with vb! said:
StargateFan said:
You better should have spent your time in reading the help instead of
creating this post. I´m quite sure, you didn´t.

You know something, this was a really offensive line. Of course I
read the help file back then and again this time around. I couldn't
make heads or tails of it. Why are the Outlook groups sometimes the
most condescending of all the MS groups? I've come back to try to
resolve this issue again now all these months later. I've gotten a
lot of fabulous help in the MS Access groups and the Excel ones re vb
so hoping that the little bit of extra knowledge would help with this.
But it's not so far. O2K vb code is different from A2K which is
different from XL2K code said:
The magic lines are:

Dim oFso as Scripting.FileSystemObject
set oFso = new Scripting.FileSystemObject
If not oFso.FolderExists(YourFolder) then
oFso.CreateFolder YourFolder
Endif

I never did get this to work and I tried again and it doesn't work
still. All that happened was that I walked away feeling very stupid
back then. Not much different this time around either. The Excel and
Access groups don't treat me as stupid. Why the different mentality,
I've always wondered.

"Best regards"? Wow.




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

All that is needed is for the above to look for the
"OutlookEmbeddedGraphics" folder and, if not there, to create it.
Michael Bauer - MVP Outlook


On Mon, 23 May 2005 15:57:48 +0200, "Michael Bauer"

Please just add the reference as I mentioned, then open the Object
Browser and watch the functions´ descriptions. Both,

See? What in heck is the object browser?
FileSystemObject.FolderExists and FileSystemObject.CreateFolder, are
really self-explanatory.

Not to a newbie they aren't.

[snip]
 
K

Ken Slovak - [MVP - Outlook]

Stepping code is a debugging process of running one code line at a time.
That way you can examine things for errors and values and make sure that
what you expect to happen at each step is really happening. To step the code
set a breakpoint in the Debug menu and then use F8 to run one code line. To
step over a called procedure and go to the next line after the procedure
call (to avoid having to step each line in the procedure) use Shift+F8.

About the only thing I can think of are permissions. Are you trying to
create a new folder in an area of the file system that isn't locked down and
is accessible to the permissions the code is running under? For example, so
setups might not allow you create a folder under C:\Program Files without
administrative rights.
 

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