none
Copy Tab Stops to New paragraph RRS feed

  • Question

  • I have a macro that will apply body styles to a non-styled (Normal only) document. Once a style has been applied, I want to apply the tab stops as they were BEFORE the style was applied.

    For example, the code below works:

    Set para1Tabs = ActiveDocument.Paragraphs(1).TabStops
    Activedocument.Paragraphs(2).Style = "Body Flush"
    ActiveDocument.Paragraphs(2).TabStops = para1Tabs

    But as soon as I change the paragraph index to 1, the third line does nothing:

    Set para1Tabs = ActiveDocument.Paragraphs(1).TabStops
    ActiveDocument.Paragraphs(1).Style = "Body Flush"
    ActiveDocument.Paragraphs(1).TabStops = para1Tabs

    It appears you cannot apply the tab stops to the original paragraph.  Please advise how I can accomplish this?

    Thursday, February 18, 2016 7:30 PM

Answers

  • Hi orlandp,

    >> It appears you cannot apply the tab stops to the original paragraph.

    I think it was caused by this code “Set para1Tabs = ActiveDocument.Paragraphs(1).TabStops”. Para1Tabs is an object reference to ActiveDocument.Paragraphs(1).TabStops. Its type is reference type, so when you set the style of paragraph, the TabStops change, and then the Para1Tabs would change. And when you set TabStops, it would not work.

    For setting TabStops with original TabStops, I think you could try the steps below:

    1. Copy and Paste the Paragraph
    2. Set the style of original paragraph
    3. Set TabStops from copied Paragraph
    4. Delete copied Paragraph

    Best Regards,

    Edward


    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, February 19, 2016 10:00 AM

All replies

  • Hi orlandp,

    >> It appears you cannot apply the tab stops to the original paragraph.

    I think it was caused by this code “Set para1Tabs = ActiveDocument.Paragraphs(1).TabStops”. Para1Tabs is an object reference to ActiveDocument.Paragraphs(1).TabStops. Its type is reference type, so when you set the style of paragraph, the TabStops change, and then the Para1Tabs would change. And when you set TabStops, it would not work.

    For setting TabStops with original TabStops, I think you could try the steps below:

    1. Copy and Paste the Paragraph
    2. Set the style of original paragraph
    3. Set TabStops from copied Paragraph
    4. Delete copied Paragraph

    Best Regards,

    Edward


    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, February 19, 2016 10:00 AM
  • Copy the whole ParagraphFormat object into a variable and then retrieve the TabStops collection. The following simple example assumes that the document contains at least five paragraphs:

    Sub tryout()
    Dim p As ParagraphFormat
    
    Set p = ActiveDocument.Paragraphs(1).Format
    
    ActiveDocument.Paragraphs(5).Style = wdStyleHeading1
    ActiveDocument.Paragraphs(5).Format.TabStops = p.TabStops
    
    End Sub


    Stefan Blom, Microsoft Word MVP

    Monday, February 29, 2016 6:59 PM