S
Steve Lang
Hi all,
I have the following (truncated) code. The problem is that after the code
has run, Outlook maintains a Write connection to the newly created backup
..pst file created at strBackupPath. I need it to be clear once the code has
finished in order to be able to do the process agin. Currently, all I can do
is close Outlook after this runs (it is part of a VB6 app) to remove the
connection.
Any ideas?
TIA and have a great day!
--
Stephen Lang
Legislative Counsel Bureau
Carson City, NV
GMT+8
slang at lcb <dot> state <dot> nv <dot> us
======CODE========
Set myOlApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
GoTo Done ' only fire if the application is already open
Else
Set myOlApp = Outlook.Application
End If
Set myNameSpace = myOlApp.GetNamespace("MAPI")
'determine the existing number of folders in outlook
NSCount = myNameSpace.Folders.Count
'add the backup location as a folder that we can use
myNameSpace.AddStore strBackupPath
Set newFolder = myNameSpace.Folders(NSCount + 1)
For i = 1 To NSCount 'dont want to include the backup folder itself
Set myFolder = myNameSpace.Folders(i)
'copy the subfolders in each to the backup dir
For y = 1 To myFolder.Folders.Count
myFolder.Folders(y).CopyTo newFolder
Next
Next
'remove backup store from outlook
myNameSpace.RemoveStore myNameSpace.Folders(NSCount + 1)
'deallocate variables
Set newFolder = Nothing
Set myFolder = Nothing
Set myNameSpace = Nothing
Set myOlApp = Nothing
=====END CODE======
I have the following (truncated) code. The problem is that after the code
has run, Outlook maintains a Write connection to the newly created backup
..pst file created at strBackupPath. I need it to be clear once the code has
finished in order to be able to do the process agin. Currently, all I can do
is close Outlook after this runs (it is part of a VB6 app) to remove the
connection.
Any ideas?
TIA and have a great day!
--
Stephen Lang
Legislative Counsel Bureau
Carson City, NV
GMT+8
slang at lcb <dot> state <dot> nv <dot> us
======CODE========
Set myOlApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
GoTo Done ' only fire if the application is already open
Else
Set myOlApp = Outlook.Application
End If
Set myNameSpace = myOlApp.GetNamespace("MAPI")
'determine the existing number of folders in outlook
NSCount = myNameSpace.Folders.Count
'add the backup location as a folder that we can use
myNameSpace.AddStore strBackupPath
Set newFolder = myNameSpace.Folders(NSCount + 1)
For i = 1 To NSCount 'dont want to include the backup folder itself
Set myFolder = myNameSpace.Folders(i)
'copy the subfolders in each to the backup dir
For y = 1 To myFolder.Folders.Count
myFolder.Folders(y).CopyTo newFolder
Next
Next
'remove backup store from outlook
myNameSpace.RemoveStore myNameSpace.Folders(NSCount + 1)
'deallocate variables
Set newFolder = Nothing
Set myFolder = Nothing
Set myNameSpace = Nothing
Set myOlApp = Nothing
=====END CODE======