VB help _please_. Incorporating this vb code to original script?

Discussion in 'Computer Support' started by fitwell, Dec 6, 2005.

  1. fitwell

    fitwell Guest

    I have this working vb code in Outlook 2000:

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




    The folder in question is the above one called
    "OutlookEmbeddedGraphics" on the desktop (in the
    "objAttachment.SaveAsFile" line above).

    The script doesn't work if the folder isn't there.

    Apparently, this needs to be added to the above to get it to work:
    *******************************************************
    Dim oFso as Scripting.FileSystemObject
    set oFso = new Scripting.FileSystemObject
    If not oFso.FolderExists(YourFolder) then
    oFso.CreateFolder YourFolder
    Endif
    *******************************************************


    But nothing I've done works. I've tried several different ways and
    have read the help file, nothing. I'm a real newbie with VB and don't
    find it easy to understand. I know there are vb experts here, so
    hoping someone here has run into this type of code before and will
    know how to make a working integration possible so that the folder is
    created on the desktop before trying to save the embedded graphics if
    it doesn't exist.

    [And yes, I have gone to the MS Outlook ngs re this but not only has
    this not been resolved, they have the worst sort of condescending
    attitude on it that I have ever come across in my 6 years of using
    ngs. The Access and Excel groups don't do this at all, it's just the
    Outlook ones! They don't know what it is to be a newbie and they just
    make you feel really stupid into the bargain <sigh>.]

    Thanks so much in advance. I'd be grateful for any help.
    fitwell, Dec 6, 2005
    #1
    1. Advertising

  2. fitwell

    why? Guest

    On Tue, 06 Dec 2005 04:57:54 -0500, fitwell wrote:

    There are several visual basic newsgroups, try one. There are also lots
    of VB tutorials.

    >I have this working vb code in Outlook 2000:


    That's vb for Visual Basic or VBScript , slight difference?

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


    <snip>

    >The folder in question is the above one called
    >"OutlookEmbeddedGraphics" on the desktop (in the
    >"objAttachment.SaveAsFile" line above).
    >
    >The script doesn't work if the folder isn't there.


    As happens when the folder doesn't exist :)

    You could of course set a variable to the returned error code and put in
    a few lines to handle it.

    You have to love these examples with no references to examples / source
    code location :)

    >Apparently, this needs to be added to the above to get it to work:
    >*******************************************************
    >Dim oFso as Scripting.FileSystemObject
    >set oFso = new Scripting.FileSystemObject


    Looks like mixed VB / VBScript, it's been a long time :) , according to
    the stull on the MSDN links below,

    Set fso = CreateObject("Scripting.FileSystemObject")

    Works in Visual Basic and VBScript


    >If not oFso.FolderExists(YourFolder) then
    > oFso.CreateFolder YourFolder
    >Endif
    >*******************************************************


    I am not going to put in an example, there are lots , search for some.


    Re difference mentioned in VB / VBScript , see the MSDN link below.

    >
    >But nothing I've done works. I've tried several different ways and


    If nothing works, try something :)

    >have read the help file, nothing. I'm a real newbie with VB and don't
    >find it easy to understand. I know there are vb experts here, so
    >hoping someone here has run into this type of code before and will


    Make things simple, create a new project / code only the FSO on it's own
    , don't test it with the Outlook bit.

    Basically write a small test to try some simple FSO things. See then
    MSDN link again.

    >know how to make a working integration possible so that the folder is
    >created on the desktop before trying to save the embedded graphics if
    >it doesn't exist.
    >
    >[And yes, I have gone to the MS Outlook ngs re this but not only has


    It's not an OL , nor Access or even Excel issue.

    Besides a VB issue you may also want to try one of the MS Scripting
    newsgroups.

    microsoft.public.scripting.scriptlets
    http://groups.google.com/group/microsoft.public.scripting.scriptlets
    looks a bit empty

    microsoft.public.scripting.vbscript
    http://groups.google.com/group/microsoft.public.scripting.vbscript

    microsoft.public.scripting.wsh
    http://groups.google.com/group/microsoft.public.scripting.wsh

    Maybe a bit heavy duty, but it's the MSDN (developer network) manual.

    Working with drives / folders.
    http://msdn.microsoft.com/library/d...n98/html/vbconprogramminginfsoobjectmodel.asp

    Fso basics / reference.
    http://msdn.microsoft.com/library/d...n-us/script56/html/FSOoriFileSystemObject.asp

    Check the examples.

    >this not been resolved, they have the worst sort of condescending
    >attitude on it that I have ever come across in my 6 years of using
    >ngs. The Access and Excel groups don't do this at all, it's just the
    >Outlook ones! They don't know what it is to be a newbie and they just
    >make you feel really stupid into the bargain <sigh>.]
    >
    >Thanks so much in advance. I'd be grateful for any help.


    Me
    why?, Dec 6, 2005
    #2
    1. Advertising

  3. fitwell

    Duane Arnold Guest

    fitwell <> wrote in
    news::

    > I have this working vb code in Outlook 2000:
    >
    > *******************************************************
    > 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
    > *******************************************************
    >
    >
    >
    >
    > The folder in question is the above one called
    > "OutlookEmbeddedGraphics" on the desktop (in the
    > "objAttachment.SaveAsFile" line above).
    >
    > The script doesn't work if the folder isn't there.


    That would be correct.

    >
    > Apparently, this needs to be added to the above to get it to work:
    > *******************************************************
    > Dim oFso as Scripting.FileSystemObject
    > set oFso = new Scripting.FileSystemObject
    > If not oFso.FolderExists(YourFolder) then
    > oFso.CreateFolder YourFolder
    > Endif
    > *******************************************************
    >


    Yes that would be what you would have to do. And it should be the first
    thing you do before you execute any other code is to check for the
    directory and if it doesn't exist, then you create the directory.


    >
    > But nothing I've done works. I've tried several different ways and
    > have read the help file, nothing. I'm a real newbie with VB and don't
    > find it easy to understand. I know there are vb experts here, so
    > hoping someone here has run into this type of code before and will
    > know how to make a working integration possible so that the folder is
    > created on the desktop before trying to save the embedded graphics if
    > it doesn't exist.


    You must do some error trapping with an ON Error GOTO and display the
    error message if there is one coming out. Maybe you don't have the
    permission to create the directory or something like that. But since you
    don't have any error trapping logic in the routine, you don't know or can
    see what has happened. All you know is that it didn't work.

    ON Error GoTo ErrCode

    Your other program logic

    ON error goto 0 ' trun it off error trapping

    Exit Sub

    ErrCode:

    MsgBox(err.message)

    END


    Duane :)
    Duane Arnold, Dec 6, 2005
    #3
  4. Re: Weird stuff in my mouth..

    Duane Arnold <> wrote:

    > And just what is wrong with tucking padding into discreet places to
    > improve the appearance of size in my personal endowments?
    Bonia Roseoflavus Limicola Bdellomicrovirus, Dec 6, 2005
    #4
  5. fitwell

    Duane Arnold Guest

    Re: Weird stuff in your mouth you don't say K-Mammy are Rug-Rats striking back?

    <What K-Mammy?>

    <Did the K-Rug-Rats put kitty litter laced by rat posion in your food trying
    to get rid of you K-Mammy-Dearest?>
    Duane Arnold, Dec 6, 2005
    #5
  6. fitwell

    Duane Arnold Guest

    Re: The K-Rug-Rats have plans for you K-Mammy.

    <They are going to take you out and it's going to be NASTY.>
    Duane Arnold, Dec 6, 2005
    #6
  7. fitwell

    fitwell Guest

    On Tue, 06 Dec 2005 19:59:22 GMT, Duane Arnold <>
    wrote:

    >fitwell <> wrote in
    >news::
    >
    >> I have this working vb code in Outlook 2000:
    >>
    >> *******************************************************
    >> 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
    >> *******************************************************
    >>
    >>
    >>
    >>
    >> The folder in question is the above one called
    >> "OutlookEmbeddedGraphics" on the desktop (in the
    >> "objAttachment.SaveAsFile" line above).
    >>
    >> The script doesn't work if the folder isn't there.

    >
    >That would be correct.
    >
    >>
    >> Apparently, this needs to be added to the above to get it to work:
    >> *******************************************************
    >> Dim oFso as Scripting.FileSystemObject
    >> set oFso = new Scripting.FileSystemObject
    >> If not oFso.FolderExists(YourFolder) then
    >> oFso.CreateFolder YourFolder
    >> Endif
    >> *******************************************************
    >>

    >
    >Yes that would be what you would have to do. And it should be the first
    >thing you do before you execute any other code is to check for the
    >directory and if it doesn't exist, then you create the directory.
    >
    >
    >>
    >> But nothing I've done works. I've tried several different ways and
    >> have read the help file, nothing. I'm a real newbie with VB and don't
    >> find it easy to understand. I know there are vb experts here, so
    >> hoping someone here has run into this type of code before and will
    >> know how to make a working integration possible so that the folder is
    >> created on the desktop before trying to save the embedded graphics if
    >> it doesn't exist.

    >
    >You must do some error trapping with an ON Error GOTO and display the
    >error message if there is one coming out. Maybe you don't have the
    >permission to create the directory or something like that. But since you
    >don't have any error trapping logic in the routine, you don't know or can
    >see what has happened. All you know is that it didn't work.
    >
    >ON Error GoTo ErrCode
    >
    >Your other program logic
    >
    >ON error goto 0 ' trun it off error trapping
    >
    >Exit Sub
    >
    >ErrCode:
    >
    >MsgBox(err.message)
    >
    >END
    >
    >
    >Duane :)


    Thanks Duane. I don't know how to do this so it's all very academic.
    I've searched and searched and haven't come up with working code as
    I'm not able to figure it out myself. I got just this type of help in
    the MS ng invovled and they said to use the object code above so I did
    after a couple hours of searching. I got nowhere and pretty fast.
    <sigh>

    So, I'm right back where I started from. I have no idea what all the
    above really means other than in broad general terms.

    Thanks much, though. I do appreciate the time and the effort. I'll
    just have to keep muddling along I guess. A year on this one and
    still no closer, really.
    fitwell, Dec 7, 2005
    #7
  8. fitwell

    old jon Guest

    "fitwell" <> wrote in message
    news:...
    >I have this working vb code in Outlook 2000:
    >
    >

    snipped for neatness
    >

    www.google.co.uk and type in VB+tutorials
    Results 1 - 10 of about 5,280,000 for VB+tutorials.
    bw..OJ
    old jon, Dec 7, 2005
    #8
  9. fitwell

    Duane Arnold Guest

    fitwell wrote:
    > On Tue, 06 Dec 2005 19:59:22 GMT, Duane Arnold <>
    > wrote:
    >
    >
    >>fitwell <> wrote in
    >>news::
    >>
    >>
    >>>I have this working vb code in Outlook 2000:
    >>>
    >>>*******************************************************
    >>>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
    >>>*******************************************************
    >>>
    >>>
    >>>
    >>>
    >>>The folder in question is the above one called
    >>>"OutlookEmbeddedGraphics" on the desktop (in the
    >>>"objAttachment.SaveAsFile" line above).
    >>>
    >>>The script doesn't work if the folder isn't there.

    >>
    >>That would be correct.
    >>
    >>
    >>>Apparently, this needs to be added to the above to get it to work:
    >>>*******************************************************
    >>>Dim oFso as Scripting.FileSystemObject
    >>>set oFso = new Scripting.FileSystemObject
    >>>If not oFso.FolderExists(YourFolder) then
    >>> oFso.CreateFolder YourFolder
    >>>Endif
    >>>*******************************************************
    >>>

    >>
    >>Yes that would be what you would have to do. And it should be the first
    >>thing you do before you execute any other code is to check for the
    >>directory and if it doesn't exist, then you create the directory.
    >>
    >>
    >>
    >>>But nothing I've done works. I've tried several different ways and
    >>>have read the help file, nothing. I'm a real newbie with VB and don't
    >>>find it easy to understand. I know there are vb experts here, so
    >>>hoping someone here has run into this type of code before and will
    >>>know how to make a working integration possible so that the folder is
    >>>created on the desktop before trying to save the embedded graphics if
    >>>it doesn't exist.

    >>
    >>You must do some error trapping with an ON Error GOTO and display the
    >>error message if there is one coming out. Maybe you don't have the
    >>permission to create the directory or something like that. But since you
    >>don't have any error trapping logic in the routine, you don't know or can
    >>see what has happened. All you know is that it didn't work.
    >>
    >>ON Error GoTo ErrCode
    >>
    >>Your other program logic
    >>
    >>ON error goto 0 ' trun it off error trapping
    >>
    >>Exit Sub
    >>
    >>ErrCode:
    >>
    >>MsgBox(err.message)
    >>
    >>END
    >>
    >>
    >>Duane :)

    >
    >
    > Thanks Duane. I don't know how to do this so it's all very academic.
    > I've searched and searched and haven't come up with working code as
    > I'm not able to figure it out myself. I got just this type of help in
    > the MS ng invovled and they said to use the object code above so I did
    > after a couple hours of searching. I got nowhere and pretty fast.
    > <sigh>
    >
    > So, I'm right back where I started from. I have no idea what all the
    > above really means other than in broad general terms.
    >
    > Thanks much, though. I do appreciate the time and the effort. I'll
    > just have to keep muddling along I guess. A year on this one and
    > still no closer, really.
    >


    You need to find a good book on VB like teach yourself VB in 21 Days
    ISBN 0-672-30715-4 it's got to be dirt cheap. There are others that
    should be dirty cheap books on how to program the MS Office products.

    Duane :)
    Duane Arnold, Dec 7, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a

    <script>alert();</script>

    =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a, Apr 13, 2004, in forum: Microsoft Certification
    Replies:
    0
    Views:
    7,809
    =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a
    Apr 13, 2004
  2. Buckaroo Banzai

    incorporating sound into an OE email

    Buckaroo Banzai, Mar 31, 2005, in forum: Computer Information
    Replies:
    2
    Views:
    315
    Buckaroo Banzai
    Apr 1, 2005
  3. n
    Replies:
    2
    Views:
    286
    Matt Ion
    Oct 31, 2004
  4. vbMark

    Questions on Incorporating fees

    vbMark, Mar 13, 2006, in forum: Computer Support
    Replies:
    1
    Views:
    376
    someone
    Mar 13, 2006
  5. nadiralishah
    Replies:
    0
    Views:
    1,130
    nadiralishah
    Jan 6, 2008
Loading...

Share This Page