Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2015, 04:39 AM
gmayor's Avatar
gmayor gmayor is offline Macro now fails in Word 2013 after working for more than a year; still works in 2007 Windows 7 64bit Macro now fails in Word 2013 after working for more than a year; still works in 2007 Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I don't use Word 2013 to do real work, as I much prefer 2010. So I cannot tell you whether it is a new problem or an established one. I can simply tell you that it is a known problem and that the same occurs here. If the behaviour has changed, it is probably attributable to an update somewhere along the line.



You can attribute the comments in real time. Declare the variable
Code:
Dim oComment as Comment
Change the line:
Code:
Selection.Comments.Add Range:=Selection.Range
to
Code:
Set oComment = Selection.Comments.Add(Range:=Selection.Range)
        If Val(Application.Version) > 14 Then
            oComment.Author = Application.UserName
        End If
If the bracketed text looks like [JS: Duis autem] then the following macro should work to leave 'Duis autem' commented
Code:
Sub TextToComments()
Dim oDoc As Document
Dim oRng As Range
Dim MyString As String
Dim myUsername As String
Dim myUserinitials As String
Dim oComment As Comment

    myUsername = Application.UserName
    myUserinitials = Application.UserInitials
    Application.UserName = "JSmith"
    Application.UserInitials = "JS"
    Application.ScreenUpdating = False
    Set oDoc = ActiveDocument
    oDoc.TrackRevisions = False
    Set oRng = oDoc.Range
    oRng.Paragraphs.LineSpacingRule = wdLineSpaceSingle
    With oRng.ParagraphFormat
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 6
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
    End With
    With oRng.Find
        Do While .Execute(FindText:="(\[*\])", MatchWildcards:=True)
            MyString = oRng.Text
            MyString = Mid(MyString, 2, Len(MyString) - 2)
            If Not Left(MyString, 3) = "TS:" Then
                MyString = Mid(MyString, InStr(1, MyString, ":") + 2)
                oRng.Text = MyString
                Set oComment = oDoc.Comments.Add(oRng, MyString)
                If Val(Application.Version) > 14 Then
                    oComment.Author = Application.UserName
                End If
                oRng.Font.Bold = False
            End If
            oRng.Collapse 0
        Loop
    End With
    oRng.Collapse 1
    oRng.Select
    Application.ScreenUpdating = True
    Application.UserName = myUsername
    Application.UserInitials = myUserinitials
lbl_Exit:
    Set oDoc = Nothing
    Set oRng = Nothing
    Set oComment = Nothing
    Exit Sub
End Sub
but it will ignore entries like
[TS: Duis autem] which I think was the intention. It should be easy enough to modify entries for TS also.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #2  
Old 09-04-2015, 06:23 AM
cyraxote cyraxote is offline Macro now fails in Word 2013 after working for more than a year; still works in 2007 Windows 7 64bit Macro now fails in Word 2013 after working for more than a year; still works in 2007 Office 2013
Novice
Macro now fails in Word 2013 after working for more than a year; still works in 2007
 
Join Date: Sep 2015
Location: Essex, MD
Posts: 24
cyraxote is on a distinguished road
Default

There are a number of problems with that:

1) It doesn't find only bold text, and I don't know how to add that to
Do While .Execute(FindText:="(\[*\])", MatchWildcards:=True)
I tried adding ", Format:=Bold" but that didn't work. It's very hard to find documentation of all the arguments in all the different formats that one can use. Can you recommend a source (online or in print)?

2) It strips off the first character of the comment text in addition to the brackets. The comments don't have a prefix followed by ":" but ":" is a valid character for the text of the comment. That is, the form is
[This is a comment; it can have internal punctuation: like this.]
I can figure that out.

3) It doesn't delete the text that's moved to the comment. I can figure that out, too.

I don't mean to sound ungrateful. Thanks for your help.
Reply With Quote
  #3  
Old 09-04-2015, 07:08 AM
cyraxote cyraxote is offline Macro now fails in Word 2013 after working for more than a year; still works in 2007 Windows 7 64bit Macro now fails in Word 2013 after working for more than a year; still works in 2007 Office 2013
Novice
Macro now fails in Word 2013 after working for more than a year; still works in 2007
 
Join Date: Sep 2015
Location: Essex, MD
Posts: 24
cyraxote is on a distinguished road
Default

I tried

Code:
With oRng.Find
        With oDoc.Content.Find
            .Font.Bold = True
        End With
        Do While .Execute(FindText:="(\[*\])", MatchWildcards:=True, _
                Format:=True)
Didn't work. I'm sure you're not surprised.
Reply With Quote
  #4  
Old 09-04-2015, 07:32 AM
cyraxote cyraxote is offline Macro now fails in Word 2013 after working for more than a year; still works in 2007 Windows 7 64bit Macro now fails in Word 2013 after working for more than a year; still works in 2007 Office 2013
Novice
Macro now fails in Word 2013 after working for more than a year; still works in 2007
 
Join Date: Sep 2015
Location: Essex, MD
Posts: 24
cyraxote is on a distinguished road
Default

Ah:
Code:
    With oRng.Find
        With .Font
            .Bold = True
        End With
        Do While .Execute(FindText:="(\[*\])", MatchWildcards:=True, _
                Format:=True)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro now fails in Word 2013 after working for more than a year; still works in 2007 formula in excel 2007 works not in 2013 piper7971 Excel 10 07-06-2015 02:09 PM
Macro now fails in Word 2013 after working for more than a year; still works in 2007 2013 presentation's animation not working in 2007 captainship PowerPoint 1 04-16-2015 09:35 AM
Macro now fails in Word 2013 after working for more than a year; still works in 2007 Macro fails to add image border in Word 2007 samhdc Word 1 03-30-2012 04:56 AM
Macro now fails in Word 2013 after working for more than a year; still works in 2007 Search always fails in Word 2007 Sachelis Word 2 01-28-2011 08:50 AM
Saving a Word 2007 document as a PDF fails dcabrames Word 20 01-21-2011 03:07 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft