문제

I'm trying, since a few days, to control a word document via vb.net. I've put some contentControl in it in order to mark the location where I have to make automatic changes. Writting in it is really easy, replacing also. Writting a continuous text with a lot of paragraphs is a little more tricky but I manage to do it via functions. Where I have more problems is by writting one title in a "Style1", a subtitle in a "Style2" and the text in "Normal style". When I write this :

With tfDocx.BodyCC("startFormulas").Range
    .Style = tfDocx.Doc.Styles("Titre 2")
    .Text = "Produits"
End With

I have the good text in the good style. But when I add this code:

With tfDocx.BodyCC("startFormulas").Range
     .Style = tfDocx.Doc.Styles("Titre 2")
     .Text = "Produits"
End With
With tfDocx.BodyCC("startFormulas").Range.Characters.Last
    .InsertParagraphAfter()
    .Style = tfDocx.Doc.Styles("Titre 3")
    .Text = "essais"
End With 

The .InsertParagraphAfter is not taken into account and when I debug it I have a single line "Produits essais" in my word document with needer of the two styles. Does someone have an idea?

도움이 되었습니까?

해결책

Converting your code to VBA (second part where you add 'essais' text) I would have this one:

With CC.Range.Characters.Last
    .InsertParagraphAfter
    .Move wdParagraph   '!!!!!!!!!
    .Style = "Nagłówek 1"
    .Text = "essais"
End With

As you can see I've added one line with '!!!! comment moving insertion point to next paragraph which was add with .InsertParagraphAfter method.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top