none
Word 2010: An undeleteable tabstop that doesn't appear in object explorer /watch window (negative position bug? RRS feed

  • Question

  • Hi

    I've got an bunch of old document from 1996 that has bar stop tabs set at -0.32 cm and 17cm ( on a4 paper)  that were manually added to act as legal black lining.

    I now need to update these documents, and want to clean them of these tabs before I make more changes to avoid confusion with the new version legal black lining.

    So an attempt to automate the removal, I've created a VBA macro that goes through each paragraph in the document, see if it's an barstop tab at either of the above locations, and delete it, but it's not working as expected because looking at the VBA object tree for the paragraph, the negative position tab isn't listed, but the positive is.

    I'm assuming that somewhere between 1996 and 2016 someone has changed the limits on where tabstops can exist, which is causing my problem. If someone could confirm this it would be greatly appreciated.

    Not using VBA,  I can't get rid of this tabstop from the ruler bar either, I have to select the text, select paragraph, then tabs, then delete the one I need, which appears to be work because according to the macro recorder it issues a clear all tabstop command, then recreates the other ones, whereas the ruler command just tries to act on the one tabstop.

    I'm going to have to modify my code to do the same, which is a bit of a nause, but shouldn't be too difficult .

    So, the question is:

    Is this behaviour a bug, an acknowledged feature, or something else?

    Thanks in advance.



    • Edited by Wolfsbane2k Thursday, March 24, 2016 10:23 AM Change Word Version
    Wednesday, March 23, 2016 7:18 PM

Answers

  • Yes, I can confirm the behaviour. The error condition occurs when reading the position of the tab-stop represented by:

    ThisDocument.Paragraphs(1).TabStops.Count

    For example, this throws the error:
    MsgBox ThisDocument.Paragraphs(1).TabStops(ThisDocument.Paragraphs(1).TabStops.Count).Position


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Wolfsbane2k Thursday, October 24, 2019 11:12 AM
    Friday, March 25, 2016 1:42 AM
  • Hi Paul,

    Yep, that solves the problem, but doesn't explain it. Is this something I should raised to Microsoft as a bug somehow?

    Proof of the issue:

    Create a new document, run the following code that creates a new tab in the positive, moves it to the negative, moves it to the positive, and watch the reported positions and total number of tabstops in the document get reduced by one when it's "Negative"

    Sub a()
        Dim t As TabStop
        Dim i As Integer
        Dim s As String
        i = 0
        
        ThisDocument.Paragraphs(1).TabStops.ClearAll
        
        'Create a new tabstop in the positive side.
        Call ThisDocument.Paragraphs(1).TabStops.Add(11, wdAlignTabBar, wdTabLeaderDots)
        'report it's location.
        For Each t In ThisDocument.Paragraphs(1).TabStops
            i = i + 1
            s = s & "," & t.Position
        Next
        Debug.Print "+ Pos _ For EACH - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        s = ""
        For i = 1 To ThisDocument.Paragraphs(1).TabStops.Count
            s = s & "," & ThisDocument.Paragraphs(1).TabStops(i).Position
        Next
        Debug.Print "+ Pos _ For I - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        
    '    Stop ' in case you want to look at the watch of
        i = 0
        s = ""
        'now move the tabstop to negative position
        ThisDocument.Paragraphs(1).TabStops(1).Position = -11
        'and report it's position.
        For Each t In ThisDocument.Paragraphs(1).TabStops
            i = i + 1
            s = s & "," & t.Position
        Next
        Debug.Print "- Pos _ For EACH - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        s = ""
        For i = 1 To ThisDocument.Paragraphs(1).TabStops.Count
            s = s & "," & ThisDocument.Paragraphs(1).TabStops(i).Position
        Next
        Debug.Print "- Pos _ For I - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        
        '    Stop ' in case you want to look at the watch of
        'Now move the Tabstop to POSITIVE again
        i = 0
        s = ""
        ThisDocument.Paragraphs(1).TabStops(1).Position = 11
        'and report it's position
        For Each t In ThisDocument.Paragraphs(1).TabStops
            i = i + 1
            s = s & "," & t.Position
        Next
        Debug.Print "+ Pos _ For EACH - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        s = ""
        For i = 1 To ThisDocument.Paragraphs(1).TabStops.Count
            s = s & "," & ThisDocument.Paragraphs(1).TabStops(i).Position
        Next
        Debug.Print "+ Pos _ For I - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        'Stop
        'Stop
    End Sub
    

    Debug output:

    + Pos _ For EACH -          NumStop-13    CountedStops-17             Positions,11,36,72,108,144,180,216,252,288,324,360,396,432,468,504,540,576
    + Pos _ For I -             NumStop-13    CountedStops-14             Positions,11,36,72,108,144,180,216,252,288,324,360,396,432
    - Pos _ For EACH -          NumStop-13    CountedStops-16             Positions,36,72,108,144,180,216,252,288,324,360,396,432,468,504,540,576
    - Pos _ For I -             NumStop-13    CountedStops-14             Positions,-11,36,72,108,144,180,216,252,288,324,360,396,432
    + Pos _ For EACH -          NumStop-13    CountedStops-17             Positions,11,36,72,108,144,180,216,252,288,324,360,396,432,468,504,540,576
    + Pos _ For I -             NumStop-13    CountedStops-14             Positions,11,36,72,108,144,180,216,252,288,324,360,396,432
    


    Notice that the Counted Stops drops from 17 to 16 when the Tabstop is negative using the "For each" method, and that the first reported tabstop is at position 36, not at the correct -11

    The discrepancy between the number of "Counted Stops" between the "For each" at 17" and the "For I" at 14 appears to be another side affect of the tabstops.count reporting 13, despite there being 17. I've not looked into this further.

    I've not tried this on word 2013 yet, but thought it worth documenting in detail in  case anyone else has this problem!



    • Edited by Wolfsbane2k Thursday, March 24, 2016 6:14 PM
    • Marked as answer by Wolfsbane2k Wednesday, March 30, 2016 11:04 AM
    Thursday, March 24, 2016 6:06 PM

All replies

  • Hi Wolfsbane2k,

    >> Is this behaviour a bug, an acknowledged feature, or something else?

    What is the version of your old word document created? I made a test with Word 2013, and I could delete the specific tab stop from ruler bar manually. I suggest you create a new word document in word 2013 and add tab stop to check whether this issue still exist.

    >> I'm going to have to modify my code to do the same, which is a bit of a nause, but shouldn't be too difficult .

    Could you achieve your requirement with this steps?

    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.


    Thursday, March 24, 2016 7:29 AM
  • Hi Wolfsbane2k,

    >> Is this behaviour a bug, an acknowledged feature, or something else?

    What is the version of your old word document created? I made a test with Word 2013, and I could delete the specific tab stop from ruler bar manually. I suggest you create a new word document in word 2013 and add tab stop to check whether this issue still exist.

    >> I'm going to have to modify my code to do the same, which is a bit of a nause, but shouldn't be too difficult .

    Could you achieve your requirement with this steps?

    Best Regards,

    Edward


    Hi Edward,

    Thanks for the reply.

    Unfortunately, I don't know what version of word the document was originally created in, but it's dated 1996, with the first version created in 1993, so it's more likely to be created in Word 3.0, then edited in Office 95 - it's not been touched since then, however it might have been created in another tool - someone has mentioned apples & wordstar on bbc micros :)

    I'm sorry - I mislead you on the MS word version - it should be 2010 - I run both across different networks, and never shall they meet.

    My re-written VBA code works well, but I'm now really want to isolate the problem a bit further just in case my code doesn't work later on ( and, as a developer I'm curious)

    So:

    With just 1 paragraph, copied and pasted from the big document into a new document where it still suffers the same "bug": - See picture for the one line in question, troublesome left hand barstop highlighted in red, right hand barstop highlighted in green.

    The VBA Watch for the Tabstops collection in question reflects 4 in paragraph.tabstops.count in the collection, with the first one (Item 1) having a position of 486 ( ~17 cm, right hand margin), as highlighted in green in the attached picture - so where is the left hand one?

    However, If I query the tabstops(1).position in the it comes in with a position of "-9" - ie, left hand margin, and the one I can't programmatically clear using the "for" loop.

    I can, manually in the immediate window, action a p.tabstops(1).clear, and it correctly clears ( after approx. 8  seconds)  but the watch window doesn't reflect the change, it still shows 4 tabs (1 custom @ 17cm, 3 default at 504,540,576)

    Now, if I reload the document, and run a p.tabstops(2).clear, p.tabstops.count returns to 13 (all non--custom, , despite there Still being a Tabstop at -9 shown in the document ruler, and the black line still being there.

    Thinking it through - running the code directly never cycles through tabstop(1), so a simple change to a "For I=1 to I=para.tabstops.count step 1" is an alternative to the "for each tabstop in " loop.

    Definitely looks like a bug somewhere in the system!

    Heres' the original code. I've got a picture, but can't add it until I'm "verified", which I thought I was. Link might work instead :

    https://social.msdn.microsoft.com/Forums/getfile/831022

    
    Sub remove_LegalBlackLines()
        Dim ta As TabStop
        Dim p As Paragraph
        Dim count As Double
        Dim countl As Double
        Dim countr As Double
        Dim dbg As Boolean
        
        dbg = True 'debug
        
        count = 0
        countl = 0
        countr = 0
        
        Debug.Print "Number of total paras: " & ThisDocument.Paragraphs.count
        For Each p In ThisDocument.Paragraphs
            Debug.Print "number of tabstops in this para: " & p.TabStops.count
            For Each ta In p.TabStops
                If ta.CustomTab = True Then
                    count = count + 1
                End If
                If ta.Alignment = wdAlignTabBar Then
                    If ta.Position = 486 Then '17.145 cm in points
                        countr = countr + 1
                        If dbg = True Then Stop
                        ta.Clear
                    ElseIf ta.Position = -9 Then 'ie, in the left hand margin
                        countl = countl + 1
                        If dbg = True Then Stop
                        ta.Clear
                    End If
                End If
            Next
        Next
        Debug.Print count, countl, countr
    End Sub

    




    • Edited by Wolfsbane2k Thursday, March 24, 2016 10:30 AM
    Thursday, March 24, 2016 10:19 AM
  • Gah.

    the following code, using a "for I = 1 to p.tabstops.count" works perfectly. Therefore I have an answer to my problem, but I don't understand why the problem is occurring.

    
    Sub remove_LegalBlackLine_ByCounting()
        Dim ta As TabStop
        Dim p As Paragraph
        Dim count As Double
        Dim countl As Double
        Dim countr As Double
        Dim dbg As Boolean
        Dim i As Integer
        dbg = False 'debug
        
        count = 0
        countl = 0
        countr = 0
        
        Debug.Print "Number of total paras: " & ThisDocument.Paragraphs.count
        For Each p In ThisDocument.Paragraphs
            Debug.Print "number of tabstops in this para: " & p.TabStops.count
            ' For i = p.TabStops.count To  1 Step -1
            For i = 1 To p.TabStops.count Step 1
                If p.TabStops.count = 13 Then Exit For 'default if no custom tabs exits
                If p.TabStops(i).CustomTab = True Then
                    count = count + 1
                    If p.TabStops(i).Alignment = wdAlignTabBar Then
                        If p.TabStops(i).Position = 486 Then '17.145 cm in points
                            countr = countr + 1
                            If dbg = True Then Stop
                            p.TabStops(i).Clear
                            i = i - 1 ' will have removed one of them, need to rescale
                        ElseIf p.TabStops(i).Position = -9 Then 'ie, in the left hand margin
                            countl = countl + 1
                            If dbg = True Then Stop
                            p.TabStops(i).Clear
                            i = i - 1 ' will have removed one of them, need to rescale
                        End If
                    End If
                End If
            Next
        Next
        Debug.Print "End - " & count & "-" & countl & "-" & countr
    End Sub




    • Marked as answer by Wolfsbane2k Thursday, March 24, 2016 10:51 AM
    • Unmarked as answer by Wolfsbane2k Thursday, March 24, 2016 10:51 AM
    • Edited by Wolfsbane2k Thursday, March 24, 2016 11:21 AM
    • Marked as answer by Wolfsbane2k Wednesday, March 30, 2016 11:04 AM
    • Unmarked as answer by Wolfsbane2k Wednesday, March 30, 2016 11:04 AM
    Thursday, March 24, 2016 10:51 AM
  • No it doesn't - If discrepancy between tabstops.count and the actual number of tabs is large, then it doesn't catch them all.

    I can probably "attempt" at creating a combined "most likely" number in the tabstops collection by doing a "for I = 1 to count" and "for each tab in paragraph.tabstop" and comparing the two, finding there are any discrepancies and then using "that" list to recreate the tabs I want to re-insert in the document afterwards...

    Edit: This is really, really annoying me now. I've spent almost 2 days on it, with the intention of it should have only taken 30 minutes, but with 60 docs to do I might be half way through manually removing them, although I'd have lost my will to live, I'm sure.


    • Edited by Wolfsbane2k Thursday, March 24, 2016 3:49 PM
    Thursday, March 24, 2016 3:47 PM
  • With Word 2010, I have no problem deleting -ve tab-stops with:

    Sub Demo()
    Application.ScreenUpdating = False
    Dim Para As Paragraph, i As Long
    For Each Para In ActiveDocument.Paragraphs
      With Para
        For i = .TabStops.Count To 1 Step -1
          With .TabStops(i)
            If .Position < 0 Then .Clear
          End With
        Next
      End With
    Next
    Application.ScreenUpdating = True
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]



    • Edited by macropodMVP Thursday, March 24, 2016 4:32 PM
    Thursday, March 24, 2016 4:31 PM
  • Hi Paul,

    Yep, that solves the problem, but doesn't explain it. Is this something I should raised to Microsoft as a bug somehow?

    Proof of the issue:

    Create a new document, run the following code that creates a new tab in the positive, moves it to the negative, moves it to the positive, and watch the reported positions and total number of tabstops in the document get reduced by one when it's "Negative"

    Sub a()
        Dim t As TabStop
        Dim i As Integer
        Dim s As String
        i = 0
        
        ThisDocument.Paragraphs(1).TabStops.ClearAll
        
        'Create a new tabstop in the positive side.
        Call ThisDocument.Paragraphs(1).TabStops.Add(11, wdAlignTabBar, wdTabLeaderDots)
        'report it's location.
        For Each t In ThisDocument.Paragraphs(1).TabStops
            i = i + 1
            s = s & "," & t.Position
        Next
        Debug.Print "+ Pos _ For EACH - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        s = ""
        For i = 1 To ThisDocument.Paragraphs(1).TabStops.Count
            s = s & "," & ThisDocument.Paragraphs(1).TabStops(i).Position
        Next
        Debug.Print "+ Pos _ For I - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        
    '    Stop ' in case you want to look at the watch of
        i = 0
        s = ""
        'now move the tabstop to negative position
        ThisDocument.Paragraphs(1).TabStops(1).Position = -11
        'and report it's position.
        For Each t In ThisDocument.Paragraphs(1).TabStops
            i = i + 1
            s = s & "," & t.Position
        Next
        Debug.Print "- Pos _ For EACH - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        s = ""
        For i = 1 To ThisDocument.Paragraphs(1).TabStops.Count
            s = s & "," & ThisDocument.Paragraphs(1).TabStops(i).Position
        Next
        Debug.Print "- Pos _ For I - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        
        '    Stop ' in case you want to look at the watch of
        'Now move the Tabstop to POSITIVE again
        i = 0
        s = ""
        ThisDocument.Paragraphs(1).TabStops(1).Position = 11
        'and report it's position
        For Each t In ThisDocument.Paragraphs(1).TabStops
            i = i + 1
            s = s & "," & t.Position
        Next
        Debug.Print "+ Pos _ For EACH - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        s = ""
        For i = 1 To ThisDocument.Paragraphs(1).TabStops.Count
            s = s & "," & ThisDocument.Paragraphs(1).TabStops(i).Position
        Next
        Debug.Print "+ Pos _ For I - ", "NumStop-" & ThisDocument.Paragraphs.TabStops.Count, "CountedStops-" & i, "Positions" & s
        'Stop
        'Stop
    End Sub
    

    Debug output:

    + Pos _ For EACH -          NumStop-13    CountedStops-17             Positions,11,36,72,108,144,180,216,252,288,324,360,396,432,468,504,540,576
    + Pos _ For I -             NumStop-13    CountedStops-14             Positions,11,36,72,108,144,180,216,252,288,324,360,396,432
    - Pos _ For EACH -          NumStop-13    CountedStops-16             Positions,36,72,108,144,180,216,252,288,324,360,396,432,468,504,540,576
    - Pos _ For I -             NumStop-13    CountedStops-14             Positions,-11,36,72,108,144,180,216,252,288,324,360,396,432
    + Pos _ For EACH -          NumStop-13    CountedStops-17             Positions,11,36,72,108,144,180,216,252,288,324,360,396,432,468,504,540,576
    + Pos _ For I -             NumStop-13    CountedStops-14             Positions,11,36,72,108,144,180,216,252,288,324,360,396,432
    


    Notice that the Counted Stops drops from 17 to 16 when the Tabstop is negative using the "For each" method, and that the first reported tabstop is at position 36, not at the correct -11

    The discrepancy between the number of "Counted Stops" between the "For each" at 17" and the "For I" at 14 appears to be another side affect of the tabstops.count reporting 13, despite there being 17. I've not looked into this further.

    I've not tried this on word 2013 yet, but thought it worth documenting in detail in  case anyone else has this problem!



    • Edited by Wolfsbane2k Thursday, March 24, 2016 6:14 PM
    • Marked as answer by Wolfsbane2k Wednesday, March 30, 2016 11:04 AM
    Thursday, March 24, 2016 6:06 PM
  • I think you'll find the issue is related to:

    1. the tab-stop count equalling the number of default tab-stops for the paragraph plus any custom tab-stops you might have; and/or

    2. for ... next loops tending to skip items when you start deleting them - unless you iterate through the loop backwards, which is what my code does.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, March 25, 2016 12:27 AM
  • Hi, and thanks for responding again.

    1) The tabstop.count, agreed, in some instances it's the default, others it's not, but it's very rarely the same as the actual number of tabs in the collection. In the example above, there is only 1 tabstop the first time you create it, but the moment you have ever gone into a negative position it adds 12, the default office 2010 number, to give 13 .I seem to recall from a thread from another MVP that if there any custom tabs, it's meant to be the total number of custom tabs. When there are no custom tabs, it returns to the default number of tabs, and I've seen this behaviour while investigating this thread.

    2) I completely agree that is usually the fault of things like this. However, if you inspect the code above, youll see it's doing no deleting, just counting, so that doesn't explain the behaviour. Please can you try it and see what results you get? ( no it's not pretty code, it's rushed together but should work out the box. Would be interested in the results the first time you run it in a new document, and then the second if you could to prove point 1)

    (The difference between the for I count and the tabstop.count is I'm printing the I value as used in the for loop, ie it has been around the loop 13 times, added one at the next, gone back to the top of the loop t complete the compare, seen its exceeded the limit, and dropped out of the loop. Really i should therefore subtract 1 from it. However, the importance is the difference in the number of objects between the two methods, not to the reported count)

    I'll try the code counting backwards after easter and see if this causes any differences, but I don't expect it to.

    Yours

    W


    Friday, March 25, 2016 1:16 AM
  • Yes, I can confirm the behaviour. The error condition occurs when reading the position of the tab-stop represented by:

    ThisDocument.Paragraphs(1).TabStops.Count

    For example, this throws the error:
    MsgBox ThisDocument.Paragraphs(1).TabStops(ThisDocument.Paragraphs(1).TabStops.Count).Position


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Wolfsbane2k Thursday, October 24, 2019 11:12 AM
    Friday, March 25, 2016 1:42 AM
  • Hi Paul,

    Brilliant, thanks for that confirmation.

    I've reported it to MS formally.

    Thanks.

    Tuesday, March 29, 2016 8:49 AM
  • Hi Wolfsbane2k,

    If there is no other issues about your original question, I would suggest you mark the helpful reply as answer to close this thread. If you have new issues, please feel free to post in this forum.

    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.


    Wednesday, March 30, 2016 2:22 AM