none
Word 2007 - Reference to a Content Control

    Question

  • How do I set a reference to a content control, so the text in the content control will be shown other places in the text in Word 2007. In Word 2003 I would use bookmarks in formfields and ref fields. I know the old formfiels are still avalible, but would like to use the new ones.

    I have tried this, but the object ceps calling itself because it activates again when I instert the text:

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    Dim con As ContentControl
    Dim bolRun As Boolean

    Application.ScreenUpdating = False

    'Opbygger en reference mellem 2 content controls
    Select Case ContentControl.Tag
        Case "Fornavn"
            ActiveDocument.SelectContentControlsByTag("refFornavn").Item(1).Range.Text = ContentControl.Range.Text
        Case "Terminalnavn"
            ActiveDocument.SelectContentControlsByTag("refTerminalnavn").Item(1).Range.Text = ContentControl.Range.Text
            ActiveDocument.SelectContentControlsByTag("refTerminalnavn").Item(2).Range.Text = ContentControl.Range.Text
        Case Else
    End Select

    Application.ScreenUpdating = True

    End Sub

    Hope to find a solution

    P.s. I think maybe if I could link a custom buildinproperty to a content control object it would work? I works if I place the content in the Title property, but that is not an option

    Friday, August 07, 2009 11:23 AM

Answers

  • Hi Richardt,

    I see a general programming issue here: A change you make in an event handler raises the event itself, resulting in an infinite recursion. To overcome this, you would have to disable the event temporarily. For example,

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    
    'Disable the event handler
    
    RemoveHandler Me.Application.ActiveDocument.ContentControlOnExit,AddressOf Sub Document_ContentControlOnExit
    
    
    
    'Add all processing code here
    
    
    'Enable back the event handler
      AddHandler Me.Application.ActiveDocument.ContentControlOnExit, AddressOf Sub Document_ContentControlOnExit
    
    End Sub
    
    
    



    Let me know if that helped.

    Regards,
    Avinash.

    NOTE - Disclaimer

    By using the following materials or sample code you agree to be bound by the license terms below and the Microsoft Partner Program Agreement the terms of which are incorporated herein by this reference. These license terms are an agreement between Microsoft Corporation (or, if applicable based on where you are located, one of its affiliates) and you. Any materials (other than sample code) we provide to you are for your internal use only. Any sample code is provided for the purpose of illustration only and is not intended to be used in a production environment. We grant you a nonexclusive, royalty-free right to use and modify the sample code and to reproduce and distribute the object code form of the sample code, provided that you agree: (i) to not use Microsoft's name, logo, or trademarks to market your software product in which the sample code is embedded; (ii) to include a valid copyright notice on your software product in which the sample code is embedded; (iii) to provide on behalf of and for the benefit of your subcontractors a disclaimer of warranties, exclusion of liability for indirect and consequential damages and a reasonable limitation of liability; and (iv) to indemnify, hold harmless, and defend Microsoft, its affiliates and suppliers from and against any third party claims or lawsuits, including attorneys' fees, that arise or result from the use or distribution of the sample code.






    Tuesday, August 11, 2009 8:32 PM

All replies

  • Hi Richardt,

    Thanks for contacting Innovate on Office Forum. We have started working on this issue and will get back to you ASAP.

    Regards,
    Avinash.
    Tuesday, August 11, 2009 4:29 PM
  • Hi Richardt,

    I see a general programming issue here: A change you make in an event handler raises the event itself, resulting in an infinite recursion. To overcome this, you would have to disable the event temporarily. For example,

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    
    'Disable the event handler
    
    RemoveHandler Me.Application.ActiveDocument.ContentControlOnExit,AddressOf Sub Document_ContentControlOnExit
    
    
    
    'Add all processing code here
    
    
    'Enable back the event handler
      AddHandler Me.Application.ActiveDocument.ContentControlOnExit, AddressOf Sub Document_ContentControlOnExit
    
    End Sub
    
    
    



    Let me know if that helped.

    Regards,
    Avinash.

    NOTE - Disclaimer

    By using the following materials or sample code you agree to be bound by the license terms below and the Microsoft Partner Program Agreement the terms of which are incorporated herein by this reference. These license terms are an agreement between Microsoft Corporation (or, if applicable based on where you are located, one of its affiliates) and you. Any materials (other than sample code) we provide to you are for your internal use only. Any sample code is provided for the purpose of illustration only and is not intended to be used in a production environment. We grant you a nonexclusive, royalty-free right to use and modify the sample code and to reproduce and distribute the object code form of the sample code, provided that you agree: (i) to not use Microsoft's name, logo, or trademarks to market your software product in which the sample code is embedded; (ii) to include a valid copyright notice on your software product in which the sample code is embedded; (iii) to provide on behalf of and for the benefit of your subcontractors a disclaimer of warranties, exclusion of liability for indirect and consequential damages and a reasonable limitation of liability; and (iv) to indemnify, hold harmless, and defend Microsoft, its affiliates and suppliers from and against any third party claims or lawsuits, including attorneys' fees, that arise or result from the use or distribution of the sample code.






    Tuesday, August 11, 2009 8:32 PM