Advertisement

05.23.2007 at 10:16AM PDT, ID: 22590595
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

Outlook Mailbox Backup to PST via vbscript

Asked by thegordo in VB Script, Visual Basic Programming, Outlook Groupware Software

Tags: , , ,

Following the post 21811473 regarding Outlook archiving, I was attempting to backup my mailbox using this script but was getting an error on the following line:

Set flr = ns.Folders(szDir)

I am assuming that it cannot find my PST file or my maillbox?

Basically all I want to do using the vbscript below or one similar, is to copy all items in my mailbox folders to a PST folder with a matching folder structure. I have created a PST and have created the same folders (Inbox, tasks etc) that are in my mailbox. I want to run this script every night as a backup so it is not important to work out the date of the items etc although it may be useful to check if they already exist in the pst file first before copying!

Can anyone help me?

Much appreciated!

JG.

Here is the script:

As to the VBScript, something like this should get the job done.  Copy and paste the code below into Notepad.  Edit it as needed, I included comments where theings can/need to be changed.  Save the file with a .vbs extension.  Double-click on the file to run it.  You could also schedule the script to be run using Windows' built-in task scheduler.  This script is very simple and is really only intended to archive the Inbox.  A more useful script would archive all folders (e.g. Tasks, Calender, etc.).

Dim olkApp, olkNS, olkRootFolder, olkArchiveFolder, intAge
'Change the age as desired
intAge = 90
Set olkApp = CreateObject("Outlook.Application")
Set olkNS = olkApp.GetNamespace("MAPI")
olkNS.Logon
'Change the Outlook folder path on the next line to that of the folder where you want archiving to begin
Set olkRootFolder = OpenMAPIFolder("\Mailbox - Doe, John\Inbox")
'Change teh Outlook folder path on the next line to that of the folder where archived items will be moved to
Set olkArchiveFolder = OpenMAPIFolder("\Personal Folders\Inbox Archive")
ProcessFolder olkRootFolder
olkNS.Logoff
Set olkNS = Nothing
Set olkRootFolder = Nothing
Set olkArchiveFolder = Nothing
Set olkApp = Nothing
WScript.Echo "All done!"
WScript.Quit

Sub ProcessFolder(olkFolder)
    Dim olkSubFolder, olkItems, olkItem, intCounter
    Set olkItems = olkFolder.Items
    For intCounter = olkItems.Count To 1 Step -1
        Set olkItem = olkItems.Item(intCounter)
        If olkItem.ReceivedTime <= (Now - intAge) Then
            olkItem.Move olkArchiveFolder
        End If
    Next
    For Each olkSubFolder In olkFolder.Folders
        ProcessFolder olkSubFolder
    Next
    Set olkSubFolder = Nothing
End Sub

'Credit where credit is due.
'The code below is not mine.  I found it somewhere on the internet but do
'not remember where or who the author is.  The original author(s) deserves all
'the credit for these functions.
Function OpenMAPIFolder(szPath)
    Dim app, ns, flr, szDir, i
    Set flr = Nothing
    Set app = CreateObject("Outlook.Application")
    If Left(szPath, Len("\")) = "\" Then
        szPath = Mid(szPath, Len("\") + 1)
    Else
        Set flr = app.ActiveExplorer.CurrentFolder
    End If
    While szPath <> ""
        i = InStr(szPath, "\")
        If i Then
            szDir = Left(szPath, i - 1)
            szPath = Mid(szPath, i + Len("\"))
        Else
            szDir = szPath
            szPath = ""
        End If
        If IsNothing(flr) Then
            Set ns = app.GetNamespace("MAPI")
            Set flr = ns.Folders(szDir)
        Else
            Set flr = flr.Folders(szDir)
        End If
    Wend
    Set OpenMAPIFolder = flr
End Function

Function IsNothing(obj)
  If TypeName(obj) = "Nothing" Then
    IsNothing = True
  Else
    IsNothing = False
  End If
End Function
Start Free Trial
[+][-]05.23.2007 at 10:46AM PDT, ID: 19143468

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2007 at 11:12AM PDT, ID: 19143717

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2007 at 11:16AM PDT, ID: 19143760

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.24.2007 at 02:12AM PDT, ID: 19147824

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2007 at 03:13AM PDT, ID: 19148046

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Visual Basic Programming, Outlook Groupware Software
Tags: outlook, pst, vbscript, mailbox
Sign Up Now!
Solution Provided By: BlueDevilFan
Participating Experts: 3
Solution Grade: A
 
 
[+][-]05.24.2007 at 04:24AM PDT, ID: 19148279

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2007 at 06:58AM PDT, ID: 19149166

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.24.2007 at 08:21AM PDT, ID: 19149970

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.20.2007 at 04:21AM PDT, ID: 19323504

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.29.2007 at 04:19AM PDT, ID: 19388304

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32