#1
|
|||
|
|||
Automatic Words replacement
Hello, could you help me create macros for automatic words replacement.
Namely random Words replacement, ie, For example, the word "therefore" is found 100 times in document. Whether it can be replaced in a random order by these words -in other words -hence -So we can conclude that -Therefore we can conclude that -on this basis we conclude that -that is, -So we conclude that but the word "therefore" must be in text too. For example, 100 words is 100% We have 8 words respectively. It is necessary that it was 12% of the words "in other words", 12% words of "hence", 12% words of "So we can conclude that" ...and so on 12 * 7 = 84 and 16 percent of words "therefore" but all these words must be randomly distributed in the text. How Can this be done? I'm sorry, i'm not programmist, i m just psychologist and don't know how it can realize, but i need it for my scientific work |
#2
|
||||
|
||||
Replacing randomly is once thing, ensuring balanced percentages amongst the replacements is quite another. For the random replacements, you could use a macro like:
Code:
Sub CheckTherefore() Application.ScreenUpdating = False Randomize Timer Dim strWords As String, i As Long, j As Long, k As Long, bCap As Boolean strWords = "therefore,in other words,hence,so we can conclude that," & _ "on this basis we conclude that,that is,so we conclude that" i = UBound(Split(strWords, ",")) + 1 With ActiveDocument.Range With .Find .Text = "therefore" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .Execute End With Do While .Find.Found bCap = (UCase(.Characters.First) = .Characters.First) Do While j = k j = Int(Rnd() * i) Loop .Text = Split(strWords, ",")(j) k = j If bCap = True Then .Characters.First = UCase(.Characters.First) .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = False End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
I ran Paul's code on a sample of 100 instances "therefore" with the following results:
therefore - 15 hence - 20 that is - 13 on this basis we can conclude - 17 so we can conclude that - 14 so we conclude that - 10 in other words - 11 You will need to consider context of course. Some of the replacements would looks silly in say: The pool is only 6 inches deep. We therefore strictly prohibit diving from either side. |
#4
|
|||
|
|||
macropod, the biggest thank you, it' s really working, the goal is achieved
gmaxey, for me it's not so critically in context of this task. Trust me, i know what i do |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Control replacement font in advance? | Katten03 | Word | 6 | 07-13-2016 04:24 AM |
automatic entering of multiple words | cliff@tauruscommercial.ca | Word | 5 | 06-03-2014 06:06 PM |
VBS Image Replacement - Appearing as Gray Box with Filename | Twily | Office | 1 | 09-12-2013 11:12 PM |
Replacement | lostsoul62 | Excel | 0 | 04-14-2012 10:07 AM |
Replacement Software | hirize | Office | 0 | 08-28-2008 02:33 PM |