locked
Delete paragraph - word automation. RRS feed

  • Question

  • Hello,

    Can any one help me how to delete a paragraph from a Word Document's object in Word automation?

    Thanks,

    Surya

    Monday, September 6, 2010 10:32 AM

Answers

  • It's a bit hard to give you exact advice given the sketchy information that you have provided.

    However. to delete a paragraph, you delete the .Range of the paragraph

    From the Visual Basic Help file for the Range.Delete method

    Deletes the specified number of characters or words.
    Syntax

    expression.Delete(Unit, Count)

    expression   Required. A variable that represents a Range object.

    Parameters

    Name Required/Optional Data Type Description
    Unit Optional Variant The unit by which the collapsed range is to be deleted. Can be one of the WdUnits constants.
    Count Optional Variant The number of units to be deleted. To delete units after the range, collapse the range and use a positive number. To delete units before the range, collapse the range and use a negative number.

    Return Value
    Long

    Remarks

    This method returns a Long value that indicates the number of items deleted, or it returns 0 (zero) if the deletion was unsuccessful.

    Example

    This example selects and deletes the contents of the active document.

    Visual Basic for Applications
    Sub DeleteSelection()
        Dim intResponse As Integer

        intResponse = MsgBox("Are you sure you want to " & _
            "delete the contents of the document?", vbYesNo)

        If intResponse = vbYes Then
            ActiveDocument.Content.Select
            Selection.Delete
        End If
    End Sub


    -- Hope this helps.

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

    "Surya Praveen" wrote in message news:96bb360a-5a55-4c71-8dea-594d3fb4e262@communitybridge.codeplex.com...

    Hello,

    Can any one help me how to delete a paragraph from a Word Document's object in Word automation?

    Thanks,

    Surya


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by Surya Praveen Tuesday, September 7, 2010 6:27 AM
    Monday, September 6, 2010 10:42 AM

All replies

  • It's a bit hard to give you exact advice given the sketchy information that you have provided.

    However. to delete a paragraph, you delete the .Range of the paragraph

    From the Visual Basic Help file for the Range.Delete method

    Deletes the specified number of characters or words.
    Syntax

    expression.Delete(Unit, Count)

    expression   Required. A variable that represents a Range object.

    Parameters

    Name Required/Optional Data Type Description
    Unit Optional Variant The unit by which the collapsed range is to be deleted. Can be one of the WdUnits constants.
    Count Optional Variant The number of units to be deleted. To delete units after the range, collapse the range and use a positive number. To delete units before the range, collapse the range and use a negative number.

    Return Value
    Long

    Remarks

    This method returns a Long value that indicates the number of items deleted, or it returns 0 (zero) if the deletion was unsuccessful.

    Example

    This example selects and deletes the contents of the active document.

    Visual Basic for Applications
    Sub DeleteSelection()
        Dim intResponse As Integer

        intResponse = MsgBox("Are you sure you want to " & _
            "delete the contents of the document?", vbYesNo)

        If intResponse = vbYes Then
            ActiveDocument.Content.Select
            Selection.Delete
        End If
    End Sub


    -- Hope this helps.

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

    "Surya Praveen" wrote in message news:96bb360a-5a55-4c71-8dea-594d3fb4e262@communitybridge.codeplex.com...

    Hello,

    Can any one help me how to delete a paragraph from a Word Document's object in Word automation?

    Thanks,

    Surya


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by Surya Praveen Tuesday, September 7, 2010 6:27 AM
    Monday, September 6, 2010 10:42 AM
  • Thanks Doug. Your answer helped me.

    Best Regards,

    Surya.

    Tuesday, September 7, 2010 6:26 AM