Word2003: Recording macro changes font colour but does not record the code.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Word2003: Recording macro changes font colour but does not record the code.

Post by ChrisGreaves »

Word2003, as usual.
For a friend:-
The attached Word2003 document contains a chunk of text "Thursday, December 01, 2022" which I have formatted locally in Courier New font. (Format, Font, Courier New, OK)
I then recorded a macro to Replace All found text in Courier New with the Found Text PLUS a change of Font Colour to Orange.

As I recorded that macro and chose Replace All, the string "Thursday, December 01, 2022" turned Orange and remained in Courier New - just as planned.
But the recorded macro does not show that it contains instruction to change the font to Orange.
And running the recorded macro does not effect the change to Orange.

This looks to me like a bug in the recording process, and it is Word2003, but still and all, if it is a bug I am surprised that it escaped notice back in those days.

Of course, it may be that I have goofed up in recording a macro. (And yes, I generally don't play with local formatting, using Character Styles instead)

I would be grateful if someone with five minutes time on their hands would have a shot at recording a macro to find Courier New and then add a non-black colour to the found text.

Thanks, Chris
You do not have the required permissions to view the files attached to this post.
He who plants a seed, plants life.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word2003: Recording macro changes font colour but does not record the code.

Post by HansV »

I recorded a macro in Word 2021. It looked like this (I didn't clean up the code in any way):

Code: Select all

Sub Macro1()
'
' Macro1 Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = 49407
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Note that neither Word 2003 nor Word 2021 records setting the font to find to Courier New. The 2021 version does specify the colour, but it doesn't work when it is run later on.

Strangely enough, this slightly edited version colours the macro text in your document but not the date...

Code: Select all

Sub Macro1()
    With Selection.Find
        .Text = ""
        .ClearFormatting
        .Font.Name = "Courier New"
        .Replacement.Text = ""
        .Replacement.ClearFormatting
        .Replacement.Font.Color = 49407
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
End Sub
Both macro recording and macro execution seems to be buggy...
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word2003: Recording macro changes font colour but does not record the code.

Post by ChrisGreaves »

HansV wrote:
18 Dec 2022, 13:27
Both macro recording and macro execution seems to be buggy...
Thanks for this confirmation, Hans. :thankyou:
I shall refrain from pointing out that this bug is now eighteen or more years old!
Cheers, Chris
He who plants a seed, plants life.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word2003: Recording macro changes font colour but does not record the code.

Post by ChrisGreaves »

HansV wrote:
18 Dec 2022, 13:27
Strangely enough, this slightly edited version colours the macro text in your document but not the date...

Code: Select all

With Selection.Find
    .Text = "^?"
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Replacement.Style = "csOrange"
End With
I have played around a little bit, first trying

Code: Select all

 .Replacement.Font.Color = wdColorOrange
and then trying

Code: Select all

.Replacement.Style = "csOrange"
where I had already defined a character style csOrange.
Both trials coloured the entire text Orange!

This must be reason #342 NOT to use local formatting. Spread the word!!!
:sad: Chris
He who plants a seed, plants life.

User avatar
Jay Freedman
Microsoft MVP
Posts: 1320
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: Word2003: Recording macro changes font colour but does not record the code.

Post by Jay Freedman »

I wrote the article https://wordmvp.com/FAQs/MacrosVBA/Modi ... dMacro.htm two decades ago, when Word 2003 was the latest (and arguably the greatest) version. Since then a lot (but nowhere near all) of the added features have been incorporated in the VBA object model, but nearly all of the old bugs are still there. When MVPs report yet again that users are complaining in the forums, the development team often replies that (a) they're too busy with planned work to fix the bugs or (b) the bugs have been in place so long that a fix would risk breaking users' existing macro code.
:hairout:

User avatar
DocAElstein
5StarLounger
Posts: 602
Joined: 18 Jan 2022, 15:59
Location: Re-routing rivers, in Hof, Beautiful Bavaria

Re: Word2003: Recording macro changes font colour but does not record the code.

Post by DocAElstein »

Hi
Jay Freedman wrote:
19 Dec 2022, 00:25
... the development team often replies that .....or (b) the bugs have been in place so long that a fix would risk breaking users' existing macro code.
:hairout:

IMO this can be a valid argument, but not one they always seem to strictly adhere to. They seem happy to change things or fix things that are not broken, example from about 2016 in Excel they started fiddling with things that finally resulted in the so called spilling stuff, which not only leads to a lot of confusion with the well established CSE way of thinking but breaks some coding which relied on certain things returning a single value and not returning an array of results which suddenly they started to, and not all at once.
There is an argument that says the spilling stuff came about by accident while they were messing about to fix some bug/ feature that no one knew about that was the reason for the whole CSE stuff in the first place…
Maybe in general if it’s a bug they are less likely to fix it, but if it’s a feature then they probably will fix it and break it
Last edited by DocAElstein on 19 Dec 2022, 10:04, edited 1 time in total.
I seriously don’t ever try to annoy. Maybe I am just the kid that missed being told about the King’s new magic suit, :(

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word2003: Recording macro changes font colour but does not record the code.

Post by ChrisGreaves »

Jay Freedman wrote:
19 Dec 2022, 00:25
I wrote the article https://wordmvp.com/FAQs/MacrosVBA/Modi ... dMacro.htm two decades ago, when Word 2003 was the latest (and arguably the greatest) version. Since then a lot (but nowhere near all) of the added features have been incorporated in the VBA object model, but nearly all of the old bugs are still there. When MVPs report yet again that users are complaining in the forums, the development team often replies that (a) they're too busy with planned work to fix the bugs or (b) the bugs have been in place so long that a fix would risk breaking users' existing macro code.
Hello Jay; excellent article, especially for newcomers.
Once we get voice recognition working (shouldn't be too hard - just need to recognize :censored: :burnup: and :please:), along with facial recognition, we should restrict Macro Recording with a limit of, say, four weeks, after which it refuses to respond at all. Think of the frustration that restriction would obviate!

On a more serious note, I have long pleaded for a stable platform in a programming environment. I rail against updates to operating system (which in my case is Windows and Word and VBA combined) where a problem mysteriously arises overnight, so I do buy into the MS argument that "a fix would risk breaking users' existing macro code", but maintain that all reported bugs should be fixed and the fixes released on at fixed periods, perhaps immediately before Christmas, then organizations can retest applications over the (often enough) two-week seasonal break.
Code that works around a bug should be documented and checked against a "fixed bug" list and go through extra testing.

Self-testing code comes into its own here.

But mainly in the given example (make Courier New font Orange) I feel betrayed by MS. The example arose in a different forum, and I had by my example hoped to convince the friend to start writing VBA code to automate Document Cleansing tasks. To my eternal shame, I have had to retire from his arena with embarrassment. Worse, my long-term goal was for recognition that document cleansing is nothing but repeated Find-Replace macros, and that all such macros could be condensed into a single Find-Replace scheme driven by a user-owned Rules Table,
That I had it all working back in 1996 and cannot now show an example of it thirty years later is the smell of shame you can detect from where you are sitting!

As for "too busy with planned work to fix the bugs" it used to be a business maxim that you took care of existing clients/commitments before you looked out for new clients/commitments.
Perhaps MS's Boss should have gone to a real business college? :laugh: :rofl:

Cheers, Chris
He who plants a seed, plants life.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word2003: Recording macro changes font colour but does not record the code.

Post by ChrisGreaves »

DocAElstein wrote:
19 Dec 2022, 07:56
Maybe in general if it’s a bug they are less likely to fix it, but if it’s a feature then they probably will fix it and break it
Don't forget the Bigger Tail Fins. That always boosts sales of the new models!
Cheers, Chris
He who plants a seed, plants life.