Word Macro issues (Solved)

yanlok1345
StarLounger
Posts: 74
Joined: 18 Oct 2023, 14:48

Word Macro issues (Solved)

Post by yanlok1345 »

Hi everyone,

I am currently working on developing a Word macro with the intention of accomplishing the following tasks:

1) Modifying the font color of all bold text within tables to wdRed.
2) Extracting hyperlinks from hyperlinked text, specifically those consisting of 6-digit numbers, found in the right column of the tables.
3) Incorporating these extracted hyperlinks into the bold and wdRed text, ensuring that they are placed in the corresponding rows.
4) Transforming all bold and wdRed text to either wdColorAuto or wdBlack.

[This issue is solved]
Last edited by yanlok1345 on 18 Apr 2024, 07:05, edited 3 times in total.

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

Re: Word Macro issues (hyperlinks)

Post by HansV »

The problem is that the character you mention is not bold.If you make it bold, the entire text in the first column will be hyperlinked.

I cannot help you with issue 2, sorry.
Best wishes,
Hans

yanlok1345
StarLounger
Posts: 74
Joined: 18 Oct 2023, 14:48

Re: Word Macro issues (hyperlinks)

Post by yanlok1345 »

HansV wrote:
16 Apr 2024, 08:42
The problem is that the character you mention is not bold.If you make it bold, the entire text in the first column will be hyperlinked.

I cannot help you with issue 2, sorry.
You've been a great help to me already. I really appreciate your effort in highlighting the concerns with the bold text. Thank you!

yanlok1345
StarLounger
Posts: 74
Joined: 18 Oct 2023, 14:48

Re: Word Macro issues (hyperlinks)

Post by yanlok1345 »

HansV wrote:
16 Apr 2024, 08:42
The problem is that the character you mention is not bold.If you make it bold, the entire text in the first column will be hyperlinked.

I cannot help you with issue 2, sorry.
May I ask why using word macro cannot change ChrW(8220) and ChrW(8221)'s font name ? But I can change it manually.

For example, the ChrW(8220) and ChrW(8221)'s font name can be changed as "Times New Roman" if i select them, then type "Times New Roman" in the font name box. But the following code doesn't work:

Code: Select all

Sub ChangeFontToTimesNewRoman()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Name = "Times New Roman"

    With Selection.Find
        .Text = ChrW(8220) & "*" & ChrW(8221)
        .Replacement.Text = "^&"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With

    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

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

Re: Word Macro issues (hyperlinks)

Post by HansV »

Your code works for me to change ChrW(8220) and ChrW(8221) to Times New Roman. I have no idea why it doesn't work for you.
Best wishes,
Hans

yanlok1345
StarLounger
Posts: 74
Joined: 18 Oct 2023, 14:48

Re: Word Macro issues (hyperlinks)

Post by yanlok1345 »

HansV wrote:
16 Apr 2024, 09:48
Your code works for me to change ChrW(8220) and ChrW(8221) to Times New Roman. I have no idea why it doesn't work for you.
I appreciate your reply. The problem I'm experiencing seems to be linked to my computer - a particular font on my regional version of Microsoft Office is causing difficulties. It's unique and affects the way ChrW(8220) and ChrW(8221) behave, preventing any changes to the font name, unless altered manually. It's unclear if the root of the issue lies therein.

Moreover, I managed to solve the problem that I've mentioned in this thread. Once again, I'm grateful for your assistance.