none
Insert programmatically Document Property Title RRS feed

  • Question

  • Hi,

    I just want to reproduce by VBA code, the following actions in Word (2007-2016) interface: Insert | Document Propriety | Title (I hope the frasing is this one, I'm using an Italian version of Word 2013); in ths way a Content Control with the BuiltInDocumentProperties("Title") is inserted in the Word doc.

    The macro recording is not helping me at all.

    I can insert a field with the Title Property; also, a RTF Control Control with the Title Property as text, but in this way I will not get the nice behoviour of the manually inserted Document Propierties: i.e. with two Document Properties inserted changing one will automatically change the other.

    Tthanks, for any suggestions, lauro

    Tuesday, April 5, 2016 11:59 AM

Answers

  • Hi,

    finally I was able to find by myself the solution. Maybe it could be usuful to others.

    Public Function InsertTitleContentControl(aRange As Range) As Boolean
       Dim bResult As Boolean
       Dim objCC As ContentControl
       Dim objMap As XMLMapping
    
       Set objCC = ActiveDocument.ContentControls.Add(wdContentControlText, aRange)
       With objCC
          .Title = "Title"
          .SetPlaceholderText , , "[Title]"
          Set objMap = .XMLMapping
       End With
       bResult = objMap.SetMapping(XPath:="/ns1:coreProperties[1]/ns0:title[1]")
       InsertTitleContentControl = bResult
    
    End Function

    Lauro


    Saturday, April 9, 2016 6:57 AM

All replies

  • Hi, Lauro2

    Use the following code to set the Document Property Tile and Display it.

    Sub SetSummaryInfo1()
          Dim dp As Object
          If Documents.Count > 0 Then
             Set dp = Dialogs(wdDialogFileSummaryInfo)
             ' Set "Title" to a new value.
             dp.Title = "My Demo Title"
             ' Set the value.
             dp.Execute
             ' Save the changes.
             ActiveDocument.Save
             ' Display the dialog.
             ' Note: Using the Display method will not keep changes
             ' manually entered into the dialog box. To keep changes
             ' manually entered in the dialog box, use the Show method.
             dp.Display
          End If
       End Sub
    

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 6, 2016 4:12 AM
    Moderator
  • Hi Deepak,

    maybe I didn't explained my goal clearly.

    I DON'T want to set the title of the document, neither show it in a Dialog Window.

    I want to insert in the content of the document a RTF Content Control with the title as its text; I want, moreover, that if the user change the text in the CC, the new text will be the new title of the document every where else. 

    Exactly what you can perform easily manually, inserting the Title Document Property from the Ribbon.

    Lauro
    Wednesday, April 6, 2016 6:29 AM
  • Hi,

    finally I was able to find by myself the solution. Maybe it could be usuful to others.

    Public Function InsertTitleContentControl(aRange As Range) As Boolean
       Dim bResult As Boolean
       Dim objCC As ContentControl
       Dim objMap As XMLMapping
    
       Set objCC = ActiveDocument.ContentControls.Add(wdContentControlText, aRange)
       With objCC
          .Title = "Title"
          .SetPlaceholderText , , "[Title]"
          Set objMap = .XMLMapping
       End With
       bResult = objMap.SetMapping(XPath:="/ns1:coreProperties[1]/ns0:title[1]")
       InsertTitleContentControl = bResult
    
    End Function

    Lauro


    Saturday, April 9, 2016 6:57 AM
  • Hi, Lauro2

    >>its good to hear that you find the solution of your issue and you have also shared a code with us. so that if some one has similar problem like you then they can get solution by your answer. Thank you for sharing code.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 11, 2016 11:27 AM
    Moderator