How to have Outlook create folder if folder is not present?

S

StargateFan

This macro is missing code to create the folder, if the folder
"Outlook embedded graphics" isn't present.

What does this need to check for this folder, pls, and to create it if
it isn't there?

************************************************************************************
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:\Documents and
Settings\Compaq_Administrator\Desktop\Outlook embedded graphics\" &
objAttachment.FileName)
Next

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

End Sub
************************************************************************************

Thanks! :blush:D
 
K

Ken Slovak - [MVP - Outlook]

FileSystemObject. FolderExists(FolderSpec As String) As Boolean

If it doesn't exist then use FileSystemObject.CreateFolder(Path As String)
As Folder
 
S

StargateFanFromWork

Ken Slovak - said:
FileSystemObject. FolderExists(FolderSpec As String) As Boolean

If it doesn't exist then use FileSystemObject.CreateFolder(Path As String)
As Folder





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


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. :blush:D
 
S

StargateFanFromWork

StargateFanFromWork said:
Ken Slovak - said:
FileSystemObject. FolderExists(FolderSpec As String) As Boolean

If it doesn't exist then use FileSystemObject.CreateFolder(Path As String)
As Folder
[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. :blush: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. :blush:D
 
K

Ken Slovak - [MVP - Outlook]

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




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. :blush: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. :blush:D
 
S

StargateFan

On Fri, 9 Mar 2007 18:18:18 -0500, "Ken Slovak - [MVP - Outlook]"

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

Thanks very much for the script. No wonder I wasn't getting the
recommendations given to work, too much needed to be done that I
didn't know about! <g>

I searched for this wshom.ocx file and I have this in the system32
fldr, just as you say, so that part will be okay.

"References", however, is missing from my Tools menu. I just did an
MS KB search and even though I haven't found anything so far related
to this
(http://support.microsoft.com/search...references+menu+missing&adv=&mode=r&cat=False),
I did find out how to add things via this article
http://support.microsoft.com/kb/264625/en-us which I'm hoping will
help me get this option. What I don't have installed for O2K turns
out to be these 3 items:

- Collaboration Data Objects
- Electronic Forms Designer Runtime
- Symantec Fax Starter Edition (Internet Mail Only Configuration)

The last one seems highly unlikely and the 2nd one somewhat unlikely
to have anything to do with this missing menu item, but would the
first item give me that option in Tools, by any chance? I don't know
how else to get it on the Tools menu.

Oh, I'm guessing it would be good to mention that I install O2K as
Corporate or Workgroup mode (because that works best for me). <g>
Don't know if that has anything to do with this.

tia! :blush:D
 
S

StargateFanFromWork

StargateFan said:
On Fri, 9 Mar 2007 18:18:18 -0500, "Ken Slovak - [MVP - Outlook]"

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

Thanks very much for the script. No wonder I wasn't getting the
recommendations given to work, too much needed to be done that I
didn't know about! <g>

I searched for this wshom.ocx file and I have this in the system32
fldr, just as you say, so that part will be okay.

"References", however, is missing from my Tools menu. I just did an
MS KB search and even though I haven't found anything so far related
to this
(http://support.microsoft.com/search/default.aspx?catalog=LCID=1033&spid=2
557&query=references+menu+missing&adv=&mode=r&cat=False),
I did find out how to add things via this article
http://support.microsoft.com/kb/264625/en-us which I'm hoping will
help me get this option. What I don't have installed for O2K turns
out to be these 3 items:

- Collaboration Data Objects
- Electronic Forms Designer Runtime
- Symantec Fax Starter Edition (Internet Mail Only Configuration)

The last one seems highly unlikely and the 2nd one somewhat unlikely
to have anything to do with this missing menu item, but would the
first item give me that option in Tools, by any chance? I don't know
how else to get it on the Tools menu.

Oh, I'm guessing it would be good to mention that I install O2K as
Corporate or Workgroup mode (because that works best for me). <g>
Don't know if that has anything to do with this.

tia! :blush:D

Trying again. As I mentioned on Friday, "References" doesn't appear in my
Tools menu.

I went ahead just now and tested this macro out anyway. Sure enough, it
doesn't work. I imagine it's because of the things above that I must do but
can't yet.

When I click on the button to which I attached the above script, it goes
into the vbe and says:

"Compile error:
User-defined type not defined"

and this "objFSO As Scripting.FileSystemObject" gets highlighted in yellow.



tia for help in resolving this. :blush:D
(I have O2K on Win2K here at the office)
 
M

Michael Bauer [MVP - Outlook]

This works without refs but you won't have help by IntelliSense:

Dim fso as Object
Set fso=createobject("Scripting.FileSystemObject")

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
The most effective way to assign Outlook categories:
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Mon, 12 Mar 2007 12:14:49 -0400 schrieb StargateFanFromWork:
StargateFan said:
On Fri, 9 Mar 2007 18:18:18 -0500, "Ken Slovak - [MVP - Outlook]"

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

Thanks very much for the script. No wonder I wasn't getting the
recommendations given to work, too much needed to be done that I
didn't know about! <g>

I searched for this wshom.ocx file and I have this in the system32
fldr, just as you say, so that part will be okay.

"References", however, is missing from my Tools menu. I just did an
MS KB search and even though I haven't found anything so far related
to this
(http://support.microsoft.com/search/default.aspx?catalog=LCID=1033&spid=2
557&query=references+menu+missing&adv=&mode=r&cat=False),
I did find out how to add things via this article
http://support.microsoft.com/kb/264625/en-us which I'm hoping will
help me get this option. What I don't have installed for O2K turns
out to be these 3 items:

- Collaboration Data Objects
- Electronic Forms Designer Runtime
- Symantec Fax Starter Edition (Internet Mail Only Configuration)

The last one seems highly unlikely and the 2nd one somewhat unlikely
to have anything to do with this missing menu item, but would the
first item give me that option in Tools, by any chance? I don't know
how else to get it on the Tools menu.

Oh, I'm guessing it would be good to mention that I install O2K as
Corporate or Workgroup mode (because that works best for me). <g>
Don't know if that has anything to do with this.

tia! :blush:D

Trying again. As I mentioned on Friday, "References" doesn't appear in my
Tools menu.

I went ahead just now and tested this macro out anyway. Sure enough, it
doesn't work. I imagine it's because of the things above that I must do but
can't yet.

When I click on the button to which I attached the above script, it goes
into the vbe and says:

"Compile error:
User-defined type not defined"

and this "objFSO As Scripting.FileSystemObject" gets highlighted in yellow.



tia for help in resolving this. :blush:D
(I have O2K on Win2K here at the office)
 
S

StargateFan

This works without refs but you won't have help by IntelliSense:

Hey, new term "IntelliSense". I'll look it up.

I found out that I was looking in the wrong Tools menu <d'uh!>. It
was in the vbe that it's found.

So I can now go back and give the other a try, too.
Dim fso as Object
Set fso=createobject("Scripting.FileSystemObject")

Thanks. :blush:D
--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
The most effective way to assign Outlook categories:
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Mon, 12 Mar 2007 12:14:49 -0400 schrieb StargateFanFromWork:
StargateFan said:
On Fri, 9 Mar 2007 18:18:18 -0500, "Ken Slovak - [MVP - Outlook]"

[snip]

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

Thanks very much for the script. No wonder I wasn't getting the
recommendations given to work, too much needed to be done that I
didn't know about! <g>

I searched for this wshom.ocx file and I have this in the system32
fldr, just as you say, so that part will be okay.

"References", however, is missing from my Tools menu. I just did an
MS KB search and even though I haven't found anything so far related
to this
(http://support.microsoft.com/search/default.aspx?catalog=LCID=1033&spid=2
557&query=references+menu+missing&adv=&mode=r&cat=False),
I did find out how to add things via this article
http://support.microsoft.com/kb/264625/en-us which I'm hoping will
help me get this option. What I don't have installed for O2K turns
out to be these 3 items:

- Collaboration Data Objects
- Electronic Forms Designer Runtime
- Symantec Fax Starter Edition (Internet Mail Only Configuration)

The last one seems highly unlikely and the 2nd one somewhat unlikely
to have anything to do with this missing menu item, but would the
first item give me that option in Tools, by any chance? I don't know
how else to get it on the Tools menu.

Oh, I'm guessing it would be good to mention that I install O2K as
Corporate or Workgroup mode (because that works best for me). <g>
Don't know if that has anything to do with this.

tia! :blush:D

Trying again. As I mentioned on Friday, "References" doesn't appear in my
Tools menu.

I went ahead just now and tested this macro out anyway. Sure enough, it
doesn't work. I imagine it's because of the things above that I must do but
can't yet.

When I click on the button to which I attached the above script, it goes
into the vbe and says:

"Compile error:
User-defined type not defined"

and this "objFSO As Scripting.FileSystemObject" gets highlighted in yellow.



tia for help in resolving this. :blush:D
(I have O2K on Win2K here at the office)
 
M

MitchellWMA

Good Morning. I'm in a new contract and finally trying to implement
the above script in my current O2K installation.

I'm getting an error message, though, which hopefully is easy to fix;
plus a question re the library in References that I can't find.

The script, again, is:
****************************************************************************************************************
Sub SaveAttachment()

'1. Make sure you have a reference set to IWshRuntimeLibrary,
' C:\WINDOWS\system32\wshom.ocx, in Tools, References of the VBE
' --------------------------------------------------------------------
' 2. This works without refs of 1, but you won't have
' help by IntelliSense:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
' Use this code above if you don't have the option in 1. above.
' If 1. is available, "blank" out these 2 lines above with ' in front.
' --------------------------------------------------------------------

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 = "(path to desktop)\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
****************************************************************************************************************
1. The part "objFSO As Scripting.FileSystemObject" gets highlighted
and the error is:
"Compile error: User-defined type not defined". Was wondering what
this meant?

2. I put the non-refs code of #2 in because I don't have the
"IWshRuntimeLibrary" as an option in this particular installation
under TOOLS > REFERENCES in the VBE here at work. I tried just
browsing to and selecting the "wshom.ocx" file and that gave the
reference of "Windows Script Host Object Model" there, but I'm
doubtful that that's what is needed though thought I'd meantion it.
The wshom.ocx exists in that folder, it's just that references doesn't
list IWshRuntimeLibrary. Thinking that you might have meant
WshRuntimeLibrary I looked for that, but there's no reference to that,
either. Could it be named something else? I looked through the tons
of stuff listed, but couldn't find anything that looked similar.

Anyway, thanks for any help re this. It'd be really nice to get this
to work once and for all. Cheers. :blush:D
 
S

Sue Mosher [MVP-Outlook]

1. The part "objFSO As Scripting.FileSystemObject" gets highlighted
and the error is:
"Compile error: User-defined type not defined". Was wondering what
this meant?

It means you haven't added a reference to the Scripting Runtime library. Either do that or declare objFSO as Object.
2. I put the non-refs code of #2 in because I don't have the
"IWshRuntimeLibrary" as an option in this particular installation
under TOOLS > REFERENCES in the VBE here at work.

Nothing in your code suggests that this library is required.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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