none
how can i loop the Repeating Section Content Controls using vb.net RRS feed

  • Question

  • I have a Repeating Section Content control.

    Like in the image : In first line i have placed Repeater control.Currently it has 4 xml nodes inside.

    i need to Print the data based on xml nodes and as well as below (10)lines by inserting new repeater control for each time.

    i have followed below code : But this is not correct. 

    For Each XMLNode1 In wordApp.ActiveDocument.ContentControls
                If XMLNode1.Type = Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRepeatingSection Then
                    XMLNode1.Range.Text = "Note"
         End If
            Next

    Can i have sample in vb.net for  Repeating  the Repeating Section Content control and inserting new Repeating Section Content control.




    Tuesday, May 6, 2014 1:24 PM

All replies

  • I am using vb.net and office 2013.

    I am writing logic to show the data in word template.Please find that :  Word Template.

    In below of CARRIER INFORMATION section (find in word template)  ...i have to loop through the data. But i I am able to print the data in first line only.

    Because first line has xml nodes. I need to print other lines as well. 

    When i google …i came to know that using repeater section ...i can print.

    Let me know is this possible to printing the lines using repeater section.

    I am able to find the Custom XML Nodes using below code.

       For Each XMlnode As Word.ContentControl In wordDoc.ContentControls

           Dim basename As String = XMlnode.XMLMapping.CustomXMLNode.BaseName.ToString()         Next

    But i am unable to find Repeating section content controls. in Word Document (Office 2013).

    What property i have to use to find that.

    I have seen in google. i got code using VBA  : VBA- Link

    Can i have a code snippet in vb.net. 

    Thanks,

    Kavitha


    Thursday, April 24, 2014 12:01 PM
  • Hi,

    If you want to find the Repeating section content controls in a document, you could loop through all the content control and pick out the ones with type of wdContentControlRepeatingSection. Then you could operate with the Repeating section content controls as you want.

    Here is a VB.Net sample to find all Repeating section content controls in a document and set content of them. app means the active Word application.

    Sub GetContentControlRepeatingSection()
        Dim XMLNode As Word.ContentControl
        Dim app As Word.Application
        For Each XMLNode In app.ActiveDocument.ContentControls
            If XMLNode.Type = Word.WdContentControlType.wdContentControlRepeatingSection Then
                XMLNode.Range.Text = "TEST"
            End If
        Next
    End Sub


    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.

    Friday, April 25, 2014 8:29 AM
    Moderator
  • Thanks for your reply Luna....

    Can i confirm with you... is this correct way to using the Repeating section part for my requirement.

    if No : which approach i have to take ...

    if yes... please see the below code.

     

    Why i did not get  wdContentControlRepeatingSection . Please see in screen shot ...Screen Shot

    Friday, April 25, 2014 2:28 PM
  • <<Why i did not get   wdContentControlRepeatingSection .>>

    Have you referenced the Word 2013 PIAs in your project? A Repeating Section content control is only available for that version. If you're not seeing it in the list, then I suspect you aren't using the right set of PIAs.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, April 25, 2014 3:44 PM
    Moderator
  • I was used  office :  Micsoft.office.library.word with 14.0.0.0

    After seeing your message...

    I have installed Word 2013 PIA using below link : 
    http://olappivottableextend.codeplex.com/wikipage?title=Office%202013%20Primary%20Interop%20Assemblies



    After installing PIA. when i go into .net tab while  adding reference...i have only Micsoft.office.library.word with 14.0.0.0 and earley vertions.

    my current ref path : C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Word.dll

    Let me know  which reference i have to add.

    Thanks !!


    Saturday, April 26, 2014 8:00 AM
  • You need to add the reference to the PIA via the COM tab.

    The .NET tab only shows PIAs that are part of the Visual Studio .NET package, which means they will be for the version of Office that was current at the time of the VS release.

    Office installs its PIAs in the GAC and, since Office is a COM application, those PIAs appear in the COM tab.


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, April 26, 2014 3:27 PM
    Moderator
  • Hi ,

    I don't have  Microsoft.Office.Interop.Word in COM Tab.

    I have installed PIA .Using  : PIA Installation (I i have installed .Net programmability Support for Microsoft Word.)

    When i searched in COM tab i did not find reference :  Microsoft.Office.Interop.Word.

    Let me know any thing I have missed.  How can i get that in COM Tab.

    Thanks !!

    Monday, April 28, 2014 6:13 AM
  • Hi,

    >>When i searched in COM tab i did not find reference :  Microsoft.Office.Interop.Word.<<

    Have you used "word" as the key words to search under the COM tab? By the way, you'd better uncheck to remove the reference of the Word Object Library 14.0.0.0.


    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 28, 2014 8:30 AM
    Moderator
  • Hi Luna,

    In COM Tab i have Microsoft  Word 15.0 Object Library  .

    After adding this : in reference folder it is showing Microsoft.office.Core.

    But i have  to add :  Microsoft.Office.Interop.Word .  Correct ?

    Monday, April 28, 2014 9:05 AM
  • Hi B kavigtha Reddy

    What you found in the COM tab is the correct entry. That provides you with the .NET namespace.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, April 28, 2014 9:19 AM
    Moderator
  • But i need to access   Word namespace.

    like  :

               Dim wordApp As New Word.Application
                Dim wordDoc As New Word.Document

    Word Name space not coming from  Microsoft.office.Core.

     so i have to add Microsoft.Office.Interop.Word .    

    Monday, April 28, 2014 9:33 AM
  • Hi,

    In fact, the Word Objects are stored in Microsoft.Office.Interop.Word NameSpace rather than Microsoft.office.Core NameSpace.

    Only after adding the reference of Microsoft Word Object Library, we could use the Microsoft.Office.Interop.Word NameSpace. If you are sure that the reference of Microsoft Word 15.0 Object Library is added successfully, you could access to all Word Objects in your VB.Net code. Also you could add the line below in the top your code.

    Imports Microsoft.Office.Interop.Word


    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 28, 2014 9:52 AM
    Moderator
  • I am sorry luna...

    In name space : it is showing only Imports Microsoft.Office.Core .

    I am not able to add the ref : Imports Microsoft.Office.Interop.Word in the namespace part.



    Monday, April 28, 2014 10:27 AM
  • Hi,

    Why do you "not able to add the ref : Imports Microsoft.Office.Interop.Word"? It's somehow strange. Are you sure that you have added reference of Microsoft Word 15.0 Object Library successfully? Would you mind sharing a screenshot or your sample project for us to understand and troubleshoot the issue?

    Please check whether the Microsoft.Office.Interop.Word 15.0.0.0 is existed under .NET Framework reference as followed. If so, you could add it.


    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.

    Tuesday, April 29, 2014 6:53 AM
    Moderator
  • Hi Luna,

    I have Microsoft.Office.Interop.Word 14.0.0.0 and below in .Net Tab

    Microsoft Word 15.0 Object Library   and below in COM Tab.

    Please see in screen shot: 

    Screen Shot

    Tuesday, April 29, 2014 1:53 PM
  • Delete the reference that's set in the .NET tab.

    Make sure you've actually set a reference to the WORD library in the COM tab (the screen shot you show is for the Office library, not the Word library).


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, April 29, 2014 5:07 PM
    Moderator
  • Thanks Cindy for your reply,

    >>Delete the reference that's set in the .NET tab.

    You mean i have to delete the reference from reference folder in solution explorer.

    Note : Microsoft.Office.library.Word 140.0.0.0 this ref i have from .Net Tab

    COM TAB: I have only Word library. How can i get Office library....

    Currently i am using Office 2013. By automatically i have to get all reference what i need for office 2013. Correct  ? 

    Thanks !!

    Wednesday, April 30, 2014 2:32 PM
  • DELETE all References currently in your project related to Word or Office.

    Go to the COM tab and add the reference to the Word object library. Normally, this should also add a reference to the corresponding Office object library. If it does not, add this reference as well.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, April 30, 2014 4:43 PM
    Moderator
  • I have found the reference in VS 2012 not in 2010.

    I have one more doubt : 

    In RepeatingSection  i have 5 custom xml nodes.

    I need to loop the RepeatingSection .How can i do this...

      For Each XMLNode1 In wordApp.ActiveDocument.ContentControls
                If XMLNode1.Type = Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRepeatingSection Then
                    XMLNode1.Range.Text = "Note"
         End If
            Next

    Thanks !!

    Monday, May 5, 2014 11:43 AM
  • Hi,

    In the code above, you have used the "For each" statement to loop through all the Content Controls, and picked out all Repeating Section Content Controls. If you want to loop through all Repeating Section Content Controls, you could try to store them firstly and then loop.

    Since your original issue has been resolved, for more new questions, in order to involve more partners of this community to share their knowledge or learn from your interaction with us, I suggest you posting a new thread in the forum.


    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.

    Tuesday, May 6, 2014 1:30 AM
    Moderator
  • Hi,

    >>Can i have sample in vb.net for  Repeating  the Repeating Section Content control and inserting new Repeating Section Content control.<<

    If you want to copy and paste the Repeating Section Content control, you could refer to the code below. But we cannot use it in the loop.

    XMLNode.Copy()
    wordApp.Selection.PasteAndFormat(Word.WdRecoveryType.wdFormatOriginalFormatting)
    


    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.

    Tuesday, May 13, 2014 10:54 AM
    Moderator