Microsoft Access VBA创建公用文件夹子文件夹

时间:2015-11-18 10:38:27

标签: ms-access outlook access-vba exchange-server

我正在寻找关于Microsoft Access VBA的一些建议 - 基本上,我被要求在表单上创建一个按钮,单击此按钮它将显示一个询问文件夹名称的框(我可以手动输入,然后单击“确定”,然后在Outlook / Exchange 2013中的公用文件夹中创建一个子文件夹。

关于此的任何信息/建议都很棒。我在互联网上尝试过一些例子,但我的VBA知识不允许我根据自己的需要修改代码。

2 个答案:

答案 0 :(得分:1)

毫无疑问,这段代码可以整理一下。它将创建一个名为“New One”的文件夹。在收件箱内。 您需要更新代码以指向正确的文件夹并询问新名称。

Sub CreateFolder()

        Dim oOutlook As Object          'Outlook.Application
        Dim nNameSpace As Object        'Outlook.Namespace
        Dim oFolder As Object

        Dim sFolder As String
        sFolder = "Mailbox - Bill Gates\Inbox"

        Set oOutlook = CreateObject("Outlook.Application")
        Set nNameSpace = oOutlook.GetNameSpace("MAPI")

        Set oFolder = GetFolderPath(sFolder)
        oFolder.Folders.Add "New One" 'Add the 'New One' folder to the Inbox.

    End Sub

    '----------------------------------------------------------------------------------
    ' Procedure : GetFolderPath
    ' Author    : Diane Poremsky
    ' Date      : 09/06/2015
    ' Original  : http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/
    ' Purpose   :
    '-----------------------------------------------------------------------------------
    Function GetFolderPath(ByVal FolderPath As String) As Object 'Outlook.Folder

        Dim oOutlook As Object          'Outlook.Application
        Dim nNameSpace As Object        'Outlook.Namespace

        Dim oFolder As Object 'Outlook.Folder
        Dim FoldersArray As Variant
        Dim i As Integer

        On Error GoTo GetFolderPath_Error

        Set oOutlook = CreateObject("Outlook.Application")

        If Left(FolderPath, 2) = "\\" Then
            FolderPath = Right(FolderPath, Len(FolderPath) - 2)
        End If
        FoldersArray = Split(FolderPath, "\")
        Set oFolder = oOutlook.Session.Folders.Item(FoldersArray(0))
        If Not oFolder Is Nothing Then
            For i = 1 To UBound(FoldersArray, 1)
                Dim SubFolders As Object
                Set SubFolders = oFolder.Folders
                Set oFolder = SubFolders.Item(FoldersArray(i))
                If oFolder Is Nothing Then
                    Set GetFolderPath = Nothing
                End If
            Next
        End If
        Set GetFolderPath = oFolder
        Exit Function

    GetFolderPath_Error:
        Set GetFolderPath = Nothing
        Exit Function
    End Function

答案 1 :(得分:0)

在VBA中使用Shell命令。您可以执行DOS命令来制作文件夹。 https://msdn.microsoft.com/en-us/library/office/gg278437%28v=office.15%29.aspx