#1
|
|||
|
|||
Checking Gender
Hi,
In a word document, I need to find all the occurrences of gender check (capital and small letters); male gender and female gender should be highlighted with different colors. I need 2 buttons, one for gender check and other to remove highlighting. The following code suited my requirement to some extent Code:
Sub GenderHighlight() Dim r As Range Dim MyList() As String Dim i As Long 'MyList = Split("dot,com,like", ",") MyList = Split(" he , He , HE , him , Him , HIM , his , His , HIS , himself , Himself , HIMSELF , she , She , SHE , her , Her , HER , hers , Hers , HERS , herself , Herself , HERSELF ", ",") For i = 0 To UBound(MyList()) Set r = ActiveDocument.Range With r.Find .Text = MyList(i) .Replacement.Highlight = wdYellow .Execute Replace:=wdReplaceAll End With Next End Sub Code:
Sub GenderHighlightRemove() Dim r As Range Dim MyList() As String Dim i As Long 'MyList = Split("dot,com,like", ",") MyList = Split(" he , He , HE , him , Him , HIM , his , His , HIS , himself , Himself , HIMSELF , she , She , SHE , her , Her , HER , hers , Hers , HERS , herself , Herself , HERSELF ", ",") For i = 0 To UBound(MyList()) Set r = ActiveDocument.Range With r.Find .Text = MyList(i) .Replacement.Highlight = wdWhite .Execute Replace:=wdReplaceAll End With Next End Sub Sharath Last edited by macropod; 07-02-2014 at 12:29 AM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
Having buttons would require the use of a userform. For regular use, you'd do better to assign keyboard shortcuts to the macros and run them from those.
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Modify Gender Check
Quote:
Thanks in advance Sharath. |
#4
|
||||
|
||||
Try:
Code:
Sub GenderHilite() Dim Rslt Rslt = InputBox("Choose an option:" & vbCr & "1. Hilight Male" & vbCr & "2. Hilight Female" _ & vbCr & "3. Un-Hilight Male" & vbCr & "4. Un-Hilight Female") Select Case Trim(Rslt) Case "": Exit Sub Case 1: Call HighlightToggle(0, wdTurquoise) Case 2: Call HighlightToggle(1, wdPink) Case 3: Call HighlightToggle(0, wdNoHighlight) Case 4: Call HighlightToggle(1, wdNoHighlight) End Select End Sub Sub HighlightToggle(Gender As Long, Hilite As Long) Dim i As Long, StrGen As String StrGen = "<[Hh][Ee]> <[Hh][Ii][MmSs]> <[Hh][Ii][Mm][Ss][Ee][Ll][Ff]>|" & _ "<[Ss][Hh][Ee]> <[Hh][Ee][Rr]> <[Hh][Ee][Rr][Ss]> <[Hh][Ee][Rr][Ss][Ee][Ll][Ff]>" StrGen = Split(StrGen, "|")(Gender) Options.DefaultHighlightColorIndex = Hilite With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Format = True .Forward = True .Wrap = wdFindContinue .MatchWildcards = True .Replacement.Highlight = True For i = 0 To UBound(Split(StrGen, " ")) .Text = Split(StrGen, " ")(i) .Execute Replace:=wdReplaceAll Next End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thanks a lot for the code
Actually, the situation is while transcribing a medical document, in history of the patient, it starts with like "A 24-year-old male/female patient...." and the rest of document goes with words like he/she, him/her, himself/herself like that...so the task here is to find any wrong occurrences (like if the patient is a male, she/herself like words which are highlighted can be deleted) to avoid gender errors in the document and to increase accuracy of the medical document. Your above code suffices the task appropriately. Instead of ourselves finding out male or female, the code should find the word male or female and rest of the gender-related words. So, could you please add 1 button or a shortcut key for checking "male or all she/he related occurrences" and other one to remove the highlight....these words when highlighted, gender errors are easily identified and in turn help us to avoid gender errors. Thanks in advance. Sharath Last edited by Sharath_MS_Forums; 07-06-2014 at 06:07 AM. Reason: Grammar |
#6
|
||||
|
||||
If you want to check male & female as well, you'll need to add those expressions to the code. For example, instead of:
StrGen = "<[Hh][Ee]> <[Hh][Ii][MmSs]> <[Hh][Ii][Mm][Ss][Ee][Ll][Ff]>|" & _ "<[Ss][Hh][Ee]> <[Hh][Ee][Rr]> <[Hh][Ee][Rr][Ss]> <[Hh][Ee][Rr][Ss][Ee][Ll][Ff]>" use: StrGen = "<[Mm][Aa][Ll][Ee]> <[Hh][Ee]> <[Hh][Ii][MmSs]> <[Hh][Ii][Mm][Ss][Ee][Ll][Ff]>|" & _ "<[Ff][Ee][Mm][Aa][Ll][Ee]> <[Ss][Hh][Ee]> <[Hh][Ee][Rr]> <[Hh][Ee][Rr][Ss]> <[Hh][Ee][Rr][Ss][Ee][Ll][Ff]>" You can keep adding similar expressions, for man & woman, boy & girl, etc. the same way. Encoding the expresions as I have done means they can be found regardless of what combination of uppercase & lowercase letters they use. As for buttons, please read what I wrote in post #2. You can't simply add buttons to a macro. Of course, if you used gender-neutral terms (e.g. patient, client, person), this wouldn't be an issue.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Quote:
I have another situation to explain you. I am using Escription software called as EditScript. In this software, when I download a file, Voice File as well as Word Document filled with Speech-recognized text will be downloaded and on the top a form (embedded within the word) will be there with all the patient-related information like patient date of birth, name, gender, etc, which I have to edit and upload. So, here, could you please let me know if there is an option automatically to check for the date of birth in "mm/dd/yyyy" format in the form field and check the age in the text below; like if the patient is a 35-year-old Caucasian male, etc....so, here 35 should be checked and if it is wrong should be highlighted, so that the transcriber can correct it and remove highlighting manually. Thanks in advance. Sharath |
#8
|
||||
|
||||
While it is possible to do that kind of comparison, the macro would need to know exactly where to look for both the date of birth, the date the form was completed and the age at that date. After all, not every date will be a date of birth or date the form was completed and not every number will be the age.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Quote:
Thanks in advance. Sharath |
#10
|
||||
|
||||
In macro terms, that's meaningless. Precisely where "on the top of the document" is each of these items.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Quote:
Thanks in advance. Sharath |
#12
|
||||
|
||||
You still haven't answered the question! Please read posts #8 & #10 again, then say explicitly where all three items are found.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Quote:
Please give me 2 to 4 hours time, I will post a screen shot regarding my question. The screen shot that I am going to attach is self-explanatory and easy for me to tell exactly what I require. Thank you. Sharath |
#14
|
|||
|
|||
Quote:
Thanks in advance. Sharath |
#15
|
||||
|
||||
Your image indicates that neither the birth date nor the date of admission are stored in the document, but in a userform. So how is the macro supposed to access these data? Without them, there is no way of doing anything with the document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
gender check |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Turning On Spell Checking Again | SQLUSA | Word | 9 | 08-01-2012 05:41 PM |
Checking n cells above's content | hanvyj | Excel | 4 | 03-22-2012 03:58 AM |
Grammar checking isssue | mahenn45 | Word | 1 | 03-01-2012 01:05 AM |
Help with checking available times | Deepy | Excel | 1 | 02-14-2011 05:06 PM |
Checking for DOS executions | ajetrumpet | Excel | 0 | 12-06-2009 02:33 PM |