none
Adding a tabstop at the center, (programmatically) RRS feed

  • Question

  • I want to set a tabstop at the center,  (programmatically)
    How can I get the width of a paragraph? (Using TextColumn.width is inefficient, because I have no way to find which column is the range in.

    thank you!

    Sunday, May 26, 2013 4:01 PM

Answers

  • In the simplest form, the following should do the trick:
    Sub CenterTabStopAtCenter()
    Dim x As Single
    x = Selection.PageSetup.TextColumns(1).Width
    
    x = x / 2
    
    Selection.ParagraphFormat.TabStops.Add _
    Position:=x, Alignment:=wdAlignTabCenter
    
    'for a left-aligned tab stop, use wdAlignTabLeft
    
    End Sub


    Stefan Blom, Microsoft Word MVP

    Sunday, May 26, 2013 5:44 PM

All replies

  • In the simplest form, the following should do the trick:
    Sub CenterTabStopAtCenter()
    Dim x As Single
    x = Selection.PageSetup.TextColumns(1).Width
    
    x = x / 2
    
    Selection.ParagraphFormat.TabStops.Add _
    Position:=x, Alignment:=wdAlignTabCenter
    
    'for a left-aligned tab stop, use wdAlignTabLeft
    
    End Sub


    Stefan Blom, Microsoft Word MVP

    Sunday, May 26, 2013 5:44 PM
  • Thanks for your reply.

    The problem is , with unequal width columns, I have no way to find the current column to get his width.

    Maybe there is another way to find the Paragraph Width ?

    Sunday, May 26, 2013 7:46 PM
  • If the selection includes more than one column, which one do you define as the "current" column? What you can do is process all columns in the selected range, setting a tab stop for all of them.


    Stefan Blom, Microsoft Word MVP


    Sunday, May 26, 2013 7:55 PM