none
Tab setting RRS feed

  • Question

  • I need a macro to highlight wherever the Tab position set greater than 1 inch in tables in the the word document (all the tabs are in Inches).

    The Macro should be able to highlight all the different alignment of the tabs (left or right or decimal etc.....in the document.

    The Line of the text marked with the tabs can be highlighted or font color can be changed to red to indicate that the line has some tab which is greater than 1 inch.

    And also I need other macro which can highlight if a hanging indent goes less than 0 inches.

    This all regards to find the text hidden manually within tables

    Could anyone help on this?

    John

    Saturday, May 31, 2014 6:19 PM

Answers

  • Hi Stefan,

    every cell could has more than 1 tab stop position.

    If you want to compare every CustomTab tab position, you could try code below in the loop:

    Dim i as Integer

    For Each oCell In oRow.Cells oCell.Select With Selection.ParagraphFormat 'check TabStops For i = 1 To .TabStops.Count If i = 1 Then If .TabStops(i).Position >= InchesToPoints(1) Then oCell.Range.HighlightColorIndex = wdYellow Exit For End If ElseIf .TabStops(i).CustomTab = True And .TabStops(i).Position - .TabStops(i - 1).Position >= InchesToPoints(1) Then oCell.Range.HighlightColorIndex = wdYellow Exit For End If Next i End With Next oCell

    If you want to find the last customTab position, please try:

    Dim customsum As Double

    customsum = ActiveDocument.DefaultTabStop For Each oCell In oRow.Cells oCell.Select With Selection.ParagraphFormat 'check TabStops For i = 1 To .TabStops.Count If .TabStops(i).CustomTab = True Then customsum = .TabStops(i).Position End If Next i If customsum >= InchesToPoints(1) Then oCell.Range.HighlightColorIndex = wdYellow End With Next oCell

    If there is no customTab, you could use ActiveDocument.DefaultTabStop to find the default tab position.

    Hope this helps.


    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, June 6, 2014 3:10 AM
    Moderator

All replies

  • Do you want to find a range that is more than 1 inch width?

    Would you mind uploading a figure that describes what the document is?

    Monday, June 2, 2014 8:05 AM
  • Are you saying that column widths are smaller than 1 inch and that the text at these tab stops are invisible? Are you trying to delete the tab stops and/or the text? Please elaborate.


    Stefan Blom, Microsoft Word MVP

    Monday, June 2, 2014 9:56 PM
  • Hi Andy,

    Thanks for your kind reply, all I need the macro needs to find wherever the tabs sets greater than 1 inch in any cell of all the tables in a word document.

    The below link has the document  I have attached  for your ref.

    https://www.dropbox.com/s/a6bnhq10onqr3rh/Find%20tabs.docx


    The document has 3 tables where all the tables has tabs in some of its cell set with greater than 1 inch, and those cells are highlighted manually with yellow shade by me for your ref.

    Is there any possibility to find and highlight the cells in the tables which has tabs with more than 1 inches through macro.

    Thanks & regards,

    John

    Tuesday, June 3, 2014 3:41 AM
  • Hi Andy/Stefan,

    Thanks for your kind reply, all I need the macro needs to find wherever the tabs sets greater than 1 inch in any cell of all the tables in a word document.

    The below link has the document  I have attached  for your ref.

    https://www.dropbox.com/s/a6bnhq10onqr3rh/Find%20tabs.docx

    The document has 3 tables where all the tables has tabs in some of its cell set with greater than 1 inch, and those cells are highlighted manually with yellow shade by me for your ref.

    Is there any possibility to find and highlight the cells in the tables which has tabs with more than 1 inches through macro?.

    Thanks & regards,

    John

    Tuesday, June 3, 2014 3:43 AM
  • Hi John,

    As far as I know, there is no object represents tab and no tab event.

    What I found is that you could set tab and record a marco for setting:

    Through Word Object Model, we can loop cells in a table, highlight any range and check the tab width of current selection.

    Here is a sample for your reference (refer to WD2000: Macro to Retrieve Text from Each Cell in a Table and HighlightColorIndex Property):

    Sub RetrieveTableItems()
       Dim oRow As Row
       Dim oCell As Cell
       Dim sCellText As String
       ' Turn on error checking.
       On Error GoTo ErrorHandler
       ' Loop through each row in the table.
       For Each oRow In ActiveDocument.Tables(1).Rows
          ' Loop through each cell in the current row.
          For Each oCell In oRow.Cells
             ' Set sCellText equal to text of the cell.
             ' Note: This section can be modified to suit
             ' your programming purposes.
             sCellText = oCell.Range
             'highlight text
    	
             oCell.Range.HighlightColorIndex = wdYellow
    '         MsgBox sCellText
          Next oCell
       Next oRow
    ErrorHandler:
       If Err <> 0 Then
          Dim Msg As String
          Msg = "Error # " & Str(Err.Number) & Chr(13) & Err.Description _
             & Chr(13) & "Make sure there is a table in the current document."
             MsgBox Msg, , "Error"
       End If
    End Sub
    

    Here is another sample to check whether the tab position of current selection is greater than 1 inch:

    With Selection.ParagraphFormat
        Width = .LeftIndent - .FirstLineIndent
        If Width >= InchesToPoints(1) Then
        MsgBox "greater than 1 inch"
    End If

    Hope this helps.


    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.

    Wednesday, June 4, 2014 9:13 AM
    Moderator
  • Note that there is a TabStops collection which you can access via a ParagraphFormat object.


    Stefan Blom, Microsoft Word MVP

    Wednesday, June 4, 2014 10:44 AM
  • Hi George,

    This macro highlights all the cells in a table, however my request would be the macro should only find and highlight wherever the tab position set grater than 1 inch any of the cells in a tables (tables only) in a word document.

    John

    Wednesday, June 4, 2014 5:42 PM
  • Hi Stefan,

    Thank you for prompting. It really helps me a lot.

    Hi John,

    I checked the document again. I found that all cells that you have highlighted had the same option: have set "Tab stop position". (select any cell -> Paragraph setting -> Tabs..)

    The default tab stop is 0.5 inch, so we can check width between two tab stops.

    If so, please try:

    Sub CheckCellTab()
       Dim oTable As Table
       Dim oRow As Row
       Dim oCell As Cell
       Dim sCellText As String
       Dim ts As TabStop
       Application.ScreenUpdating = False
       ' Turn on error checking.
       On Error GoTo ErrorHandler
       'loop all tables
       For Each oTable In ActiveDocument.Tables
       ' Loop through each row in the table.
           For Each oRow In oTable.Rows
              ' Loop through each cell in the current row.
              For Each oCell In oRow.Cells
                 oCell.Select
                 With Selection.ParagraphFormat
        '            check TabStops
                    For Each ts In .TabStops
                        If ts.Next.Position - ts.Position <> InchesToPoints(0.5) Then
                            oCell.Range.HighlightColorIndex = wdYellow
                            Exit For
                        End If
                    Next
                 End With
              Next oCell
           Next oRow
        Next oTable
        Application.ScreenUpdating = True
    ErrorHandler:
        If Err <> 0 Then
           Dim Msg As String
           Msg = "Error # " & Str(Err.Number) & Chr(13) & Err.Description _
              & Chr(13) & "Make sure there is a table in the current document."
              MsgBox Msg, , "Error"
        End If
    End Sub

    The result of the first table:

    Hope this helps.


    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.

    Thursday, June 5, 2014 2:47 AM
    Moderator
  • Hi George,

    Thanks much for your swift respond, this code is very helpful and a great job.

    However it highlighted wherever the tab stop position exist even the cell has tab stop position less than 1 inch.

    For Ex: If a table has 10 cells where the 8 cells have the tabs stop position sets with less than 1 inch and the rest of the 2 cells have the tab stop position sets with more than 1 inch, in this case the macro highlight all the 10 cells in the table rather than highlight only 2 cells since it has tab stop position in all the cells.

    My request is the macro should only highlight the tab position wherever it sets greater than 1 inch and not to highlight the cells which has the tab stop position less than 1 inch.

    It was my mistake that I didn’t set the tab stop position less than 1 inch in other cells apart from the highlighted cells when I upload the document.

    If I can explain anything better please let me know.

    Thursday, June 5, 2014 8:23 PM
  • Hi George,

    For better clarity, please check the below the link.

    https://www.dropbox.com/s/ifc62bhid7namw9/Find%20tabsv1.docx

    In this document there are few cells I manually set tabs position greater than 1 inches which are highlighted with green and in some of the cells the tabs sets with less than 1 inch which are highlighted with red.

    I need the macro only find and highlight the cells which I manually highlight with green not the red.

    Please help on this.

    John

    Friday, June 6, 2014 2:12 AM
  • Hi Stefan,

    every cell could has more than 1 tab stop position.

    If you want to compare every CustomTab tab position, you could try code below in the loop:

    Dim i as Integer

    For Each oCell In oRow.Cells oCell.Select With Selection.ParagraphFormat 'check TabStops For i = 1 To .TabStops.Count If i = 1 Then If .TabStops(i).Position >= InchesToPoints(1) Then oCell.Range.HighlightColorIndex = wdYellow Exit For End If ElseIf .TabStops(i).CustomTab = True And .TabStops(i).Position - .TabStops(i - 1).Position >= InchesToPoints(1) Then oCell.Range.HighlightColorIndex = wdYellow Exit For End If Next i End With Next oCell

    If you want to find the last customTab position, please try:

    Dim customsum As Double

    customsum = ActiveDocument.DefaultTabStop For Each oCell In oRow.Cells oCell.Select With Selection.ParagraphFormat 'check TabStops For i = 1 To .TabStops.Count If .TabStops(i).CustomTab = True Then customsum = .TabStops(i).Position End If Next i If customsum >= InchesToPoints(1) Then oCell.Range.HighlightColorIndex = wdYellow End With Next oCell

    If there is no customTab, you could use ActiveDocument.DefaultTabStop to find the default tab position.

    Hope this helps.


    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, June 6, 2014 3:10 AM
    Moderator
  • Hi George,<o:p></o:p>

    You are genius, your macro saves all my time and it works perfect.<o:p></o:p>

    A final request, there is a table in the word file I have attached in the below link, in the table there are few value or character or letter manually hidden by using tabs or manually adjust the row height by using the option row height.exactly.<o:p></o:p>

    I have highlighted the cell with red which is hidden by using tab setting and with green which is hidden by adjusting row height.<o:p></o:p>

    Is there any way to find out the cells and highlight it through your macro.<o:p></o:p>

    In simple, is there any way to find and highlight the value or letter in a cell which is not appear in print view mode.<o:p></o:p>

    I attached the file in the below link for your kind review.<o:p></o:p>

    https://www.dropbox.com/s/iakn99w9bady9b8/Find%20valuev3.docx<o:p></o:p>

    I am really sorry for troubling you again and again, It would be really grateful, if you look and resolve this issue.<o:p></o:p>

    Could you please look on this?<o:p></o:p>

    John<o:p></o:p>

    Saturday, June 7, 2014 2:08 AM
  • Hi John,

    Since the post has been for a long time, I would suggest you posting a new thread for the final request.

    After that, other community members will join in.

    Thanks for your understanding.


    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.

    Sunday, June 8, 2014 4:59 PM
    Moderator
  • Hi George, Thanks for your timely help and suggestion, It has been posted as a new thread under the heading of "Macro to uncover hidden content". John
    Wednesday, June 11, 2014 8:52 AM