Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using VBScript, how do I update Microsoft Outlook Inbox folder before accessing it in VBS?

Using VBScript, how do I update Microsoft Outlook Inbox folder before accessing it in VBS?

Using VBScript, how do I update Microsoft Outlook Inbox folder before accessing it in VBS?

The following is a VBScript (VBS) that I use the check for and process certain Outlook emails and attachments. The script finds the emails via their email address and subject. It then saves the attachment in a folder and moves the email to a folder within Outlook.

CODE -->

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutlook = CreateObject("Outlook.Application")

Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Call SaveAndMoveAttachment("'subject 1'", objFolder)
Call SaveAndMoveAttachment("'subject 2'", objFolder)
Call SaveAndMoveAttachment("'subject 3'", objFolder)

Set objFSO = Nothing
Set objOutlook = Nothing
Set objNamespace = Nothing

Sub SaveAndMoveAttachment(sSubject, objFolder)
    Set colItems = objFolder.Items
    Set colFilteredItems = colItems.Restrict("[Subject] = " & sSubject)

    If colFilteredItems.count = 0 then
        Msgbox "An email with subject " & sSubject & " in it was not found in your Outlook Inbox"
    end if

    For Each objMessage In colFilteredItems
        Set colAttachments = objMessage.Attachments 
        intCount = colAttachments.Count

        If intCount <> 0  and objMessage.Sender.Address = "support@somesite.com" Then
            For i = 1 To intCount
                strFileName = "Z:\somepath\" & objMessage.Attachments.Item(i).FileName
                objMessage.Attachments.Item(i).SaveAsFile strFileName
                'move the message to somefolder folder
                Set objFoldersomefolder = objNamespace.GetDefaultFolder(olFolderInbox).Folders("somefolder")

                objMessage.Move objFoldersomefolder
        End If

    Set colFilteredItems = Nothing
    Set colAttachments = Nothing
    Set colItems = Nothing
End Sub 
I need to update the inbox if client is closed.
Another person told me to:
Add logon step between above 2 lines

WSCript.Sleep 2000

And i stuck to add this 3 lines in the code. Can someone help me for this? Thanks :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close