Publisher crashes changing format of paragraph in Selection Textrange.

Joined
Feb 20, 2017
Messages
4
Reaction score
0
I have some program-like text. I would like to change the color of all the lines in the selected text that start with an asterisk to green. Publisher Crashes, hard, with my VBA attempt.

I added some debugging code. Tracked it down, but I don't understand why it's failing.
The issue is with the "Set t = " statement.

With .Paragraphs(), works fine. Without, losing the selection (either explicitly with the .Unselect, or implicitly with the p.font.color...=...) corrupts the "t" variable, and Publisher crashes on next use of "t".

Seems natural to me to use: "set t = Selection.Textrange", yet it fails catastrophically and I could find no other reports of similar failures. So, this would seem to me to be a clear Publisher defect, but also a gap in my understanding. Anyone care to explain? (Fails in Publisher 2010 on both Win Vista and Windows 10.)

Thanks.

Sample lines:
==========

DateType,EventName,Date,Format,PictureReference

* Edit this file in a text editor such as Notepad.
* (In theory, you can use Excel, but Excel will mangle the dates.)

Program:
========
Code:
Sub RecolorParagraphs()
    Dim p As TextRange          ' Paragraph.
    Dim t As TextRange
    Dim i As Integer
   
    ' Make sure something selected.
    ' If "Permission Denied" error, then selection point not active at all.
    ' Just select some text.
    If Selection.TextRange.Start = Selection.TextRange.End Then
        MsgBox "Select something before running. Bye."
        Exit Sub
    End If
   
    ' Remember original selection.
    Set t = Selection.TextRange.Paragraphs(1, Selection.TextRange.ParagraphsCount) ' Works.
    ' Set t = Selection.TextRange     ' Fails: Publisher Crash shortly after the UnSelect.
    '                                   Fails in Publisher 2010 on both Win Vista and Win 10.
   
    For i = 1 To t.ParagraphsCount
        Debug.Print "Line(" & i & ")='" & t.Paragraphs(i) & "'"
    Next i
     
    ActiveDocument.Selection.Unselect
   
    For i = 1 To t.ParagraphsCount
         Debug.Print "Again(" & i & ")='" & t.Paragraphs(i) & "'"
    Next i
   
    ' Turn comment lines (begin with '*') green.
    For i = 1 To t.ParagraphsCount
        Set p = t.Paragraphs(i)
        If p.Characters(1).Text = "*" Then
            p.Font.Color.RGB = RGB(0, 128, 0)
        End If
    Next i
       
End Sub
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top