Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-01-2014, 08:20 PM
Sharath_MS_Forums Sharath_MS_Forums is offline Checking Gender Windows 7 32bit Checking Gender Office 2007
Novice
Checking Gender
 
Join Date: Jul 2014
Location: India
Posts: 14
Sharath_MS_Forums is on a distinguished road
Default 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
Thanks in advance.
Sharath

Last edited by macropod; 07-02-2014 at 12:29 AM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 07-02-2014, 12:31 AM
macropod's Avatar
macropod macropod is offline Checking Gender Windows 7 32bit Checking Gender Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-02-2014, 03:03 AM
Sharath_MS_Forums Sharath_MS_Forums is offline Checking Gender Windows 7 32bit Checking Gender Office 2007
Novice
Checking Gender
 
Join Date: Jul 2014
Location: India
Posts: 14
Sharath_MS_Forums is on a distinguished road
Default Modify Gender Check

Quote:
Originally Posted by macropod View Post
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.
Could you please let me know the code to use different colors to male gender and female gender, and also to highlight the "male" or "female" word that occurs in the document.

Thanks in advance

Sharath.
Reply With Quote
  #4  
Old 07-02-2014, 03:19 PM
macropod's Avatar
macropod macropod is offline Checking Gender Windows 7 32bit Checking Gender Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 07-06-2014, 05:55 AM
Sharath_MS_Forums Sharath_MS_Forums is offline Checking Gender Windows 7 32bit Checking Gender Office 2007
Novice
Checking Gender
 
Join Date: Jul 2014
Location: India
Posts: 14
Sharath_MS_Forums is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 07-06-2014, 06:10 AM
macropod's Avatar
macropod macropod is offline Checking Gender Windows 7 32bit Checking Gender Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 07-06-2014, 06:29 AM
Sharath_MS_Forums Sharath_MS_Forums is offline Checking Gender Windows 7 32bit Checking Gender Office 2007
Novice
Checking Gender
 
Join Date: Jul 2014
Location: India
Posts: 14
Sharath_MS_Forums is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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.
Thanks a lot.

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
Reply With Quote
  #8  
Old 07-06-2014, 06:39 AM
macropod's Avatar
macropod macropod is offline Checking Gender Windows 7 32bit Checking Gender Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #9  
Old 07-06-2014, 06:54 AM
Sharath_MS_Forums Sharath_MS_Forums is offline Checking Gender Windows 7 32bit Checking Gender Office 2007
Novice
Checking Gender
 
Join Date: Jul 2014
Location: India
Posts: 14
Sharath_MS_Forums is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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.
Yeah, that's true, so, can it be done like this. The code should check for date of birth and insert the age as of today on the top of the document.

Thanks in advance.

Sharath
Reply With Quote
  #10  
Old 07-06-2014, 04:07 PM
macropod's Avatar
macropod macropod is offline Checking Gender Windows 7 32bit Checking Gender Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Sharath_MS_Forums View Post
The code should check for date of birth and insert the age as of today on the top of the document.
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]
Reply With Quote
  #11  
Old 07-08-2014, 01:21 AM
Sharath_MS_Forums Sharath_MS_Forums is offline Checking Gender Windows 7 32bit Checking Gender Office 2007
Novice
Checking Gender
 
Join Date: Jul 2014
Location: India
Posts: 14
Sharath_MS_Forums is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
In macro terms, that's meaningless. Precisely where "on the top of the document" is each of these items.
I wanted the age in number to be inserted on the first line of the document.

Thanks in advance.

Sharath
Reply With Quote
  #12  
Old 07-08-2014, 01:24 AM
macropod's Avatar
macropod macropod is offline Checking Gender Windows 7 32bit Checking Gender Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #13  
Old 07-08-2014, 02:46 AM
Sharath_MS_Forums Sharath_MS_Forums is offline Checking Gender Windows 7 32bit Checking Gender Office 2007
Novice
Checking Gender
 
Join Date: Jul 2014
Location: India
Posts: 14
Sharath_MS_Forums is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
You still haven't answered the question! Please read posts #8 & #10 again, then say explicitly where all three items are found.

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
Reply With Quote
  #14  
Old 07-08-2014, 05:46 AM
Sharath_MS_Forums Sharath_MS_Forums is offline Checking Gender Windows 7 32bit Checking Gender Office 2007
Novice
Checking Gender
 
Join Date: Jul 2014
Location: India
Posts: 14
Sharath_MS_Forums is on a distinguished road
Default

Quote:
Originally Posted by Sharath_MS_Forums View Post
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
Please check the attachment. In the JPEG, there is a field called Birth Date; this is field from which I want to take the date and compare it with today and give me the age on the first line of the document.

Thanks in advance.

Sharath
Attached Images
File Type: jpg ToMSOfficeForums.JPG (234.5 KB, 24 views)
Reply With Quote
  #15  
Old 07-08-2014, 05:53 AM
macropod's Avatar
macropod macropod is offline Checking Gender Windows 7 32bit Checking Gender Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

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
Checking Gender Grammar checking isssue mahenn45 Word 1 03-01-2012 01:05 AM
Checking Gender 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft