Changing Paragraph Indent Margins via VBA

Posted on 2006-04-21
Last Modified: 2008-03-06
Hello all.

I have a macro which moves through the document based on the paragraphs collection.

It then tests the paragraph indent and changes it based on what it finds.

The problem being, the macro runs exceedingly slowly on any document that contains a table.

How would I go about excluding tables from being found and evaluated by the Paragraphs collection?

Any advice would be helpful.

Question by:Drakos13
    LVL 76

    Accepted Solution

    You don't show your code, so it's not clear if your problem is finding the tables, or excluding them from the process.
    This code will still find paragraphs in tables, but will not process them.

    Sub IndentParagraphs()
        Dim para As Paragraph
        For Each para In ActiveDocument.Paragraphs
            If para.Range.Tables.Count = 0 Then
                para.Format.LeftIndent = CentimetersToPoints(3)
            End If
        Next para
    End Sub

    Author Comment

    Another winner.

    That works perfectly.

    Thanks again!

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
    A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
    This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now