Jump to content

Recommended Posts

Posted

Hi everyone,

I have looked through the forums and I am unable to find where I could open an existing .pst file in Outlook.

I have the pst file on a cd, and will copy it to a local folder (lets say "C:\Outlook").

I just want to have outlook add the pst file to the navigation pane.

I know i can do this manually by clicking File, Open, open pst, then selecting the file, but I would like to use the UDF/COM feature? to add it instead. Is this possible?

Any help would be greatly appreciated,

Rich

Posted

I found this VBA code if this helps(I am not familiar with vba):

Sub SetNewStore(strFileName as String, strDisplayName as String)

Dim objOL as Outlook.Application.

Dim objNS as Outlook.Namespace

Dim objFolder as Outlook.MAPIFolder

Set objOL = CreateObject("Outlook.Application")

Set objNS = objOL.GetNamespace("MAPI")

objNS.AddStore strFileName

Set objFolder = objNS.Folders.GetLast

objFolder.Name = strDisplayName

Set objOL = Nothing

Set objNS = Nothing

Set objFolder = Nothing

End Sub

Posted

I have the copy part all set, and setting it read only. Just need some help with adding the pst to Outlook now.

Any suggestions?

Thanks,

Rich

Posted

After messing around with the fields i figured it out, heres the script I ended up using to add the personal folder to outlook 2003:

$personalfoldername="C:\outlook\archivetickets.pst"

DIM $objOL = "Outlook.Application"

Dim $objNS = "Outlook.Namespace"

Dim $objFolder = "Outlook.MAPIFolder"

$objOL = ObjCreate("Outlook.Application")

$objNS = $objOL.GetNameSpace("MAPI")

$objNS.Addstore ($personalfoldername)

:)

Rich

  • 10 years later...
Posted (edited)

This is my bulk pst add to outlook, with error captcha (silent or not):

 

 

 

#include <File.au3>

$silent=1

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
; This is my custom defined error handler
Func MyErrFunc()
   if $silent=0 then
      Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"    & @CRLF  & @CRLF & _
                "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
                "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
                "err.number is: "       & @TAB & hex($oMyError.number,8)  & @CRLF & _
                "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
                "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
                "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
                "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
                "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
               )
   endif
Endfunc

$pathToScan="C:\Users\cbarreto\Desktop\Recuperacion1\Recovered data 06-30-2018 at 17_14_01\FAT32\More lost files\Outlook Email file"
$SCANPST="C:\Program Files\Microsoft Office 15\root\office15\scanpst.exe" ;Im using Office2013 x64 search it manually

if StringInStr($pathToScan,"\",0,1,StringLen($pathToScan))=0 then $pathToScan=$pathToScan&"\"

$FileList = _FileListToArray($pathToScan)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf

For $i = 1 To $FileList[0]
   $fileName=$FileList[$i]
   $fileAbsoluteName=$pathToScan    &$FileList[$i]
   ;MsgBox(0, $i, $fileAbsoluteName)
   ConsoleWrite($i&" "&$fileName&"...")
   ;ShellExecuteWait("c:\CSCANPST\CSCANPST.exe "&$SCANPST&" "&$fileAbsoluteName)
   addToOutlook()
   ;exit
Next

Func addToOutlook()
   DIM $objOL = "Outlook.Application"
   Dim $objNS = "Outlook.Namespace"
   Dim $objFolder = "Outlook.MAPIFolder"
   $objOL = ObjCreate("Outlook.Application")
   $objNS = $objOL.GetNameSpace("MAPI")
   $objNS.Addstore ($fileAbsoluteName)
   ConsoleWrite("OK"&@CRLF)
EndFunc

Edited by barresoft
Posted

Not sure why you would resurrect this 11 year old post?  However since its already been done, I would have suggested using something like below or utilizing Waters excellent Outlook UDF.

#include <File.au3>

If FileExists(RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE", "")) = False Then Exit MsgBox(16, "Outlook Error", "Outlook is not installed on this system")

Global $g_bSilent = False
Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
Global $g_sPathToScan = $g_bSilent = False ? FileSelectFolder("Please Select PST Folder", "") : @LocalAppDataDir & "\Recovered PST Files"
Global $g_aPSTFiles = _FileListToArrayRec($g_sPathToScan, "*.pst", 1, 0, 0, 2)
    If @error Then Exit MsgBox(16, "", "No Files\Folders Found.")
For $i = 1 To $g_aPSTFiles[0]
    _AddToOutlook($g_aPSTFiles[$i])
Next

Func _AddToOutlook($p_sPstFilePath)
    Local $objOL = ObjCreate("Outlook.Application")
    Local $objNS = $objOL.GetNameSpace("MAPI")
    $objNS.Addstore ($p_sPstFilePath)
   ConsoleWrite("Added : " & $p_sPstFilePath & @CRLF)
EndFunc

; This is my custom defined error handler
Func MyErrFunc()
   If $g_bSilent Then
      Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"    & @CRLF  & @CRLF & _
                "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
                "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
                "err.number is: "       & @TAB & hex($oMyError.number,8)  & @CRLF & _
                "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
                "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
                "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
                "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
                "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
               )
   EndIf
Endfunc

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...