none
inexplicable Newlines before and after a table in a Richtext-ContentControl RRS feed

  • Question

  • Hi,

    i'm writing an Add-In for Word, which creates a ContentControl (wdContentControlRichText) and inserts a table. But additionally there are 2 newlines, which i can't delete with Range.Delete - i tried it hard for several hours :/

    Code fo adding the table:

    var range = Globals.ThisAddIn.Application.Selection.Range;
    var contentControl = range.Document.ContentControls.Add(WdContentControlType.wdContentControlRichText, range);
    var table = contentControl.Range.Tables.Add(contentControl.Range, 10, 2, WdDefaultTableBehavior.wdWord9TableBehavior);
    table.PreferredWidthType = WdPreferredWidthType.wdPreferredWidthPercent;
    table.PreferredWidth = 100;
    table.Range.Font.Name = "Courier New";
    var caption = "Beschriftung";
    table.Range.InsertCaption(WdCaptionLabelID.wdCaptionTable, caption, false, WdCaptionPosition.wdCaptionPositionBelow);
    

    Result:

    http://h-4.abload.de/img/tabelle_in_ccooiq.png 

    rgds otis

    Friday, March 11, 2011 2:28 PM

Answers

  • Using VBA, the paragraphs that you want to eliminate will not be present with the following

    Dim rng As Range
    Dim cc As ContentControl
    Dim tbl As Table
    Dim caption As String
    Set rng = Selection.Range
    Set cc = ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlRichText, rng)
    Set tbl = ActiveDocument.Tables.Add(cc.Range, 10, 2, WdDefaultTableBehavior.wdWord9TableBehavior)
    tbl.PreferredWidthType = WdPreferredWidthType.wdPreferredWidthPercent
    tbl.PreferredWidth = 100
    tbl.Range.Font.Name = "Courier New"
     caption = "Beschriftung"
    Set rng = cc.Range
    rng.Collapse wdCollapseEnd
    rng.InsertCaption WdCaptionLabelID.wdCaptionTable, caption, False, WdCaptionPosition.wdCaptionPositionBelow
    Set rng = cc.Range
    rng.Collapse wdCollapseStart
    rng.Delete
     -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Otis B Driftwood" wrote in message news:50754a80-68e3-4c42-a076-8104de711c3f@communitybridge.codeplex.com...

    Hi,

    i'm writing an Add-In for Word, which creates a ContentControl (wdContentControlRichText) and inserts a table. But additionally there are 2 newlines, which i can't delete with Range.Delete - i tried it hard for several hours :/
    Code fo adding the table:


    var range = Globals.ThisAddIn.Application.Selection.Range; var contentControl = range.Document.ContentControls.Add(WdContentControlType.wdContentControlRichText, range); var table = contentControl.Range.Tables.Add(contentControl.Range, 10, 2, WdDefaultTableBehavior.wdWord9TableBehavior); table.PreferredWidthType = WdPreferredWidthType.wdPreferredWidthPercent; table.PreferredWidth = 100; table.Range.Font.Name = "Courier New"; var caption = "Beschriftung"; table.Range.InsertCaption(WdCaptionLabelID.wdCaptionTable, caption, false, WdCaptionPosition.wdCaptionPositionBelow);

    Result:
    http://h-4.abload.de/img/tabelle_in_ccooiq.png
    rgds otis


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Saturday, March 12, 2011 10:57 AM

All replies

  • Using VBA, the paragraphs that you want to eliminate will not be present with the following

    Dim rng As Range
    Dim cc As ContentControl
    Dim tbl As Table
    Dim caption As String
    Set rng = Selection.Range
    Set cc = ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlRichText, rng)
    Set tbl = ActiveDocument.Tables.Add(cc.Range, 10, 2, WdDefaultTableBehavior.wdWord9TableBehavior)
    tbl.PreferredWidthType = WdPreferredWidthType.wdPreferredWidthPercent
    tbl.PreferredWidth = 100
    tbl.Range.Font.Name = "Courier New"
     caption = "Beschriftung"
    Set rng = cc.Range
    rng.Collapse wdCollapseEnd
    rng.InsertCaption WdCaptionLabelID.wdCaptionTable, caption, False, WdCaptionPosition.wdCaptionPositionBelow
    Set rng = cc.Range
    rng.Collapse wdCollapseStart
    rng.Delete
     -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "Otis B Driftwood" wrote in message news:50754a80-68e3-4c42-a076-8104de711c3f@communitybridge.codeplex.com...

    Hi,

    i'm writing an Add-In for Word, which creates a ContentControl (wdContentControlRichText) and inserts a table. But additionally there are 2 newlines, which i can't delete with Range.Delete - i tried it hard for several hours :/
    Code fo adding the table:


    var range = Globals.ThisAddIn.Application.Selection.Range; var contentControl = range.Document.ContentControls.Add(WdContentControlType.wdContentControlRichText, range); var table = contentControl.Range.Tables.Add(contentControl.Range, 10, 2, WdDefaultTableBehavior.wdWord9TableBehavior); table.PreferredWidthType = WdPreferredWidthType.wdPreferredWidthPercent; table.PreferredWidth = 100; table.Range.Font.Name = "Courier New"; var caption = "Beschriftung"; table.Range.InsertCaption(WdCaptionLabelID.wdCaptionTable, caption, false, WdCaptionPosition.wdCaptionPositionBelow);

    Result:
    http://h-4.abload.de/img/tabelle_in_ccooiq.png
    rgds otis


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Saturday, March 12, 2011 10:57 AM
  • Thanks! It helped me alot and it's working exactly as i wanted :)

     

    rgds otis

    Saturday, March 12, 2011 11:30 AM