Solved

Wordmerge

Posted on 2016-09-26
8
67 Views
Last Modified: 2016-09-26
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

0
Comment
Question by:RIAS
  • 5
  • 3
8 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 41815826
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
0
 

Author Comment

by:RIAS
ID: 41815830
Cheers! will try and get back!
0
 

Author Comment

by:RIAS
ID: 41815833
wdFindContinue is not declared?
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41815834
corrected code
 
   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

1
 

Author Comment

by:RIAS
ID: 41815851
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

0
 

Author Comment

by:RIAS
ID: 41815853
Cheers!.

Is there a way I can replace the text with lower case?
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 41815856
try by replacing ^& in the replacement text with to:
0
 

Author Closing Comment

by:RIAS
ID: 41816162
Cheers mate!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question