Avatar of RIAS
RIAS
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Wordmerge

Hello,
I have a code for wordmerge but, the match case doesnt seem to work .
I have TO:  and To: to replace and it is not able to distinguish between the cases and replaces everthing .

                    If dtSQL.Rows(0)("Guestname").ToString Is DBNull.Value = False Then

                        With oDoc.Content.Find

                            .Forward = True
                            .Format = False
                            .MatchCase = True
                            .MatchWholeWord = True
                            .MatchWildcards = True
                            .MatchSoundsLike = True
                            .MatchAllWordForms = False
                            .Font.Bold = False
                            oDoc.Content.Find.Execute(FindText:="TO:",
                    ReplaceWith:="TO: " & dtSQL.Rows(0)("Guestname").ToString, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
                        End With
                    End If

Open in new window

Visual Basic.NET.NET ProgrammingVBA

Avatar of undefined
Last Comment
RIAS

8/22/2022 - Mon
Rgonzo1971

Hi,

pls try

    With oDoc.Content.Find
        .Text = "to:"
        .Replacement.Text = "^& " & dtSQL.Rows(0)("Guestname").ToString
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
    End With

Open in new window

Regards
RIAS

ASKER
Cheers! will try and get back!
RIAS

ASKER
wdFindContinue is not declared?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RIAS

ASKER
Mate,

This code worked
 With oDoc.Content.Find
                            .Text = "To:"
                            .Replacement.Text = "^& " & dtSQL.Rows(0)("Guestname").ToString
                            .Forward = True
                            .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
                            .Format = False
                            .MatchCase = False
                            .MatchWholeWord = False
                            .MatchWildcards = False
                            .MatchSoundsLike = False
                            .MatchAllWordForms = False
                            .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)


                        End With

Open in new window

RIAS

ASKER
Cheers!.

Is there a way I can replace the text with lower case?
Rgonzo1971

try by replacing ^& in the replacement text with to:
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
RIAS

ASKER
Cheers mate!