none
Excel VBA app to create word documents in outlook public folders RRS feed

  • Question

  • Hello,

    I've written some code in VBA to run a form in excel, and from this create spreadsheet entries and a word doc, which I then want to store in outlook public folders. 

    The trouble is finding out how to add / create word documents in public folders. I can see how to post items, with attached documents, but I want to create actual documents in the folders, as we use public folders for storing our documents at work.

    I tried using the code below, albeit to create an empty excel document and not a word one, but it looks like the message class for the item type I am using has been deprecated, and you are no longer able to create documents as outlook items?  

         

    Dim objOL As Outlook.Application, objFolder As Outlook.MAPIFolder
    Dim objNS As Outlook.Namespace, objPostItem As Outlook.PostItem

    Set objOL = New Outlook.Application
    Set objNS = objOL.GetNamespace("MAPI")

    Set objFolder = objNS.PickFolder
    Set objDocItem = objFolder.Items.Add(olExcelWorkSheetItem)

    no idea what properties to set to make this work as doesnt seem to be documented...


    is there any other approach I can take? 

    many thanks for any advice

    Monday, January 13, 2014 4:10 PM

Answers

  • Have you tried to call objDocItem.Attachments.Add (followed by objDocItem.save) to add the actual attachment?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, January 13, 2014 4:21 PM
  • Hello platy,

    I have noticed that you use the PostItem class. Instead, you need to use the DocumentClass for embedding Office documents, for example:

    Dim objDoc as Outlook.DocumentItem

    Set objDoc = objFolder.Items.Add("IPM.Document")

    objDoc.Attachments.Add strFilePath objDoc.Subject = objDoc.Attachments.Item(1).DisplayName objDoc.Save

    Also you can find a similar forum thread - Send Excel Workbook Automatically to Public Folders.
    Tuesday, January 14, 2014 3:53 PM

All replies

  • Have you tried to call objDocItem.Attachments.Add (followed by objDocItem.save) to add the actual attachment?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, January 13, 2014 4:21 PM
  • Hello platy,

    I have noticed that you use the PostItem class. Instead, you need to use the DocumentClass for embedding Office documents, for example:

    Dim objDoc as Outlook.DocumentItem

    Set objDoc = objFolder.Items.Add("IPM.Document")

    objDoc.Attachments.Add strFilePath objDoc.Subject = objDoc.Attachments.Item(1).DisplayName objDoc.Save

    Also you can find a similar forum thread - Send Excel Workbook Automatically to Public Folders.
    Tuesday, January 14, 2014 3:53 PM