Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    coding POST to Public folder (O2k, O03, Outlook, Word )

    Hi folks

    Controlling a Post operation from MS Word vba.

    I am trying to write VBA that POSTs activedocument as attachment to a nominated public folder.
    The resulting post turns up in the in-box.
    I can send successfully to the correct public folder if I specify
    .to = "publicfoldername@domain name"

    It seems that modifying the send routine with substitituions for item type to olPostItem etc is insufficient, and using .post instead of .send is insufficient.

    Do I need to somehow specify a defaultFolder in my code ..

    Thanks in anticipation..
    Geof

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: coding POST to Public folder (O2k, O03, Outlook, Word )

    It would help to see your code where you create the Outlook Post Item. A document can't be attached to a folder, but can be attached to a Post Item, so I assume that's what you mean. I haven't done this (I don't have permissions to post to any public folders), but I assume you'd need to set the target folder something like:

    Set objFldr = Application.GetNamespace("MAPI").GetDefaultFolder( olPublicFoldersAllPublicFolders)
    Set objFldr = objFldr.Folders("SubFolder").Folders("TargetFolder ")

    Then see if you can either make this folder the Current Folder and use the Post Method

    ActiveExplorer.SelectFolder objFldr
    myPostItem.Post

    or use the Items.Add Method of the Folder

    objFldr.Items.Add(myPostItem)
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: coding POST to Public folder (O2k, O03, Outlook, Word )

    Hello John
    Thanks for your ktime and help.
    Your suggestion helps in that I can now select the correct folder ..
    The resultant post however still appears in the inbox.

    I still have an issue if Outlook is not running but here is the code at present.
    The code I found on a m/soft site
    -----------------------
    Sub PostDocumentAsAttachment()

    Dim bStarted As Boolean
    Dim oOutlookApp As New Outlook.Application
    Dim oItem As Outlook.PostItem
    Dim oFldr
    'Set oOutlookApp = GetObject(, "Outlook.Application") ---- I get myself in a knot here probably related to bStarted variable and quitting further down. A side issue. -------------
    Set oItem = oOutlookApp.CreateItem(olPostItem)

    Set oFldr = oOutlookApp.GetNamespace("MAPI").GetDefaultFolder( olPublicFoldersAllPublicFolders) ' John
    Set oFldr = oFldr.Folders("Shared Resources")
    ActiveExplorer.SelectFolder oFldr


    On Error Resume Next

    If Len(ActiveDocument.Path) = 0 Then
    MsgBox "Document needs to be saved first"
    Exit Sub
    End If

    If Err <> 0 Then
    Set oOutlookApp = CreateObject("Outlook.Application")
    bStarted = True
    End If


    With oItem
    .Subject = ActiveDocument.Name
    .Attachments.Add Source:=ActiveDocument.FullName, DisplayName:="Document as attachment"
    .Post
    End With
    'oFldr.Items.Add (oItem) - as a suggested alternative



    If bStarted Then
    oOutlookApp.Quit
    End If

    Set oItem = Nothing
    Set oOutlookApp = Nothing

    End Sub
    -----------------------------

    Cheers and thanks again.

    Geof

  4. #4
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: coding POST to Public folder (O2k, O03, Outlook, Word )

    Hello again John
    You put me on the right track ..

    here is my solution
    -------
    Sub PostDocumentAsAttachment()

    Dim bStarted As Boolean
    Dim oOutlookApp As New Outlook.Application
    Dim oFldrItems
    Dim oItem As Outlook.PostItem
    Dim oFldr


    On Error Resume Next

    If Len(ActiveDocument.Path) = 0 Then
    MsgBox "Document needs to be saved first"
    Exit Sub
    End If

    If Err <> 0 Then
    Set oOutlookApp = CreateObject("Outlook.Application")
    bStarted = True
    End If

    Set oOutlookApp = GetObject(, "Outlook.Application")
    Set oFldr = oOutlookApp.GetNamespace("MAPI").GetDefaultFolder( olPublicFoldersAllPublicFolders)
    Set oFldr = oFldr.Folders("Shared Resources")
    ActiveExplorer.SelectFolder oFldr

    Set oFldrItems = oFldr.Items
    Set oItem = oOutlookApp.CreateItem(olPostItem)

    With oFldrItems.Add
    .Subject = ActiveDocument.Name
    .Attachments.Add Source:=ActiveDocument.FullName, DisplayName:="Document as attachment"
    .Post
    End With


    If bStarted Then
    oOutlookApp.Quit
    End If
    Set oFldr = Nothing
    Set oFldrItems = Nothing
    Set oItem = Nothing
    Set oOutlookApp = Nothing

    End Sub
    ----------

    Cheers and thanks again

    Geof

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: coding POST to Public folder (O2k, O03, Outlook, Word )

    If you wish to, you should be able to

    Dim oFldr as Outlook.MAPIFolder
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •