开发者

Using VB6 to search for existence of DataFile in Outlook

开发者 https://www.devze.com 2022-12-15 04:54 出处:网络
I am wanting to write an Add-In for Outlook 2003 which, when Outlook is opened, search for the existence of a datafile called DMSDataStore and if it doesn\'t exist will install the datafile.I have man

I am wanting to write an Add-In for Outlook 2003 which, when Outlook is opened, search for the existence of a datafile called DMSDataStore and if it doesn't exist will install the datafile. I have managed to create the Add-In using VB6 and it runs when I open Outlook. However I haven't found the best/easiest way to search for the existence of the datafile. If the datafile exists it is visible within Ou开发者_如何转开发tlook under the user's mailbox, much the same as an archive folder is. I would like to be able to search for it by name which is DMSDataFile.

I did try - Set tmpInbox = parentFolder.Folders("DMSDataFile") This works OK if the datafile exists but will throw an error if it doesn't. I can create an error handler which will then install the datafile but this doesn't seem like a very tidy way of doing things.

I guess I might have to recursively search for the datafile. Can someone let me know what is the best / easiest way to search for the datafile using the name of the datafile and give me some code with which to do it.


This is an example from VBA.

Public Function GetFolder(strFolderPath As String) As Object ''MAPIFolder
'' strFolderPath needs to be something like
''   "Public Folders\All Public Folders\Company\Sales" or
''   "Personal Folders\Inbox\My Folder"

Dim apOL As Object ''Outlook.Application
Dim objNS As Object ''Outlook.NameSpace
Dim colFolders As Object 'Outlook.Folders
Dim objFolder As Object 'Outlook.MAPIFolder
Dim arrFolders() As String
Dim i As Long

On Error GoTo TrapError

    strFolderPath = Replace(strFolderPath, "/", "\")
    arrFolders() = Split(strFolderPath, "\")

    Set apOL = CreateObject("Outlook.Application")
    Set objNS = apOL.GetNamespace("MAPI")


    On Error Resume Next

    Set objFolder = objNS.Folders.Item(arrFolders(0))

    If Not objFolder Is Nothing Then
        For i = 1 To UBound(arrFolders)
            Set colFolders = objFolder.Folders
            Set objFolder = Nothing
            Set objFolder = colFolders.Item(arrFolders(i))

            If objFolder Is Nothing Then
                Exit For
            End If
        Next
    End If

On Error GoTo TrapError

    Set GetFolder = objFolder
    Set colFolders = Nothing
    Set objNS = Nothing
    Set apOL = Nothing

Exit_Proc:
    Exit Function

TrapError:
    MsgBox Err.Number & ": " &  Err.Description

End Function
0

精彩评论

暂无评论...
验证码 换一张
取 消