Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2015, 11:45 AM
cikanoz87 cikanoz87 is offline How to replace a letter to random letter with different color? Windows 7 32bit How to replace a letter to random letter with different color? Office 2007
Novice
How to replace a letter to random letter with different color?
 
Join Date: Jun 2015
Posts: 4
cikanoz87 is on a distinguished road
Default How to replace a letter to random letter with different color?

Hello,



Is there any way in MS Office Word 2007, to replace a letter to random letter with different color automatically? For example:

change "a" to random letter.
"Mama gave me an apple" to
"Mdme gsve me tn rpple"

As far as I know, I can use Replace All, and Format -> Font -> Color (in Ctrl+H), but no random letter selection to be replaced.

Thanks in advance.
Reply With Quote
  #2  
Old 06-16-2015, 04:28 PM
macropod's Avatar
macropod macropod is offline How to replace a letter to random letter with different color? Windows 7 64bit How to replace a letter to random letter with different color? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

No. Word has no built-in randomising functions for a Replace.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-17-2015, 01:19 AM
gmayor's Avatar
gmayor gmayor is offline How to replace a letter to random letter with different color? Windows 7 64bit How to replace a letter to random letter with different color? Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I love these seemingly pointless puzzles
You cannot do it with replace, but you can do it with a macro http://www.gmayor.com/installing_macro.htm

Code:
Option Explicit

Sub RandomLetters()
Dim oRng As Range
Dim oFind As Range
Dim i As Long
Dim strChar As String
Start:
    strChar = InputBox("Replace which character?", , "a")
    If Len(strChar) > 1 Or Not IsLetter(asc(strChar)) Then
        MsgBox "Enter a single character from the ranges A-Z or a-z only", vbCritical
        GoTo Start
    End If
    Set oFind = Selection.Range
    Set oRng = Selection.Range
    For i = 1 To oRng.Characters.Count
        With oRng.Find
            Do While .Execute(FindText:=strChar, MatchCase:=True)
                If oRng.InRange(oFind) Then
                    oRng.Text = RandomLetter(strChar)
                    oRng.Font.ColorIndex = wdRed
                End If
                oRng.Collapse wdCollapseEnd
            Loop
        End With
    Next i
End Sub

Private Function IsLetter(ByVal i As Integer) As Boolean
Select Case i
        Case 65 To 90, 97 To 122
            IsLetter = True
        Case Else
            IsLetter = False
    End Select
lbl_Exit:
    Exit Function
End Function

Private Function RandomLetter(strChar As String) As String
    Select Case asc(strChar)
        Case 65 To 90
            RandomLetter = Chr(65 + Rnd() * 10000000 Mod 26)
        Case 97 To 122
            RandomLetter = Chr(97 + Rnd() * 10000000 Mod 26)
        Case Else
            RandomLetter = strChar
    End Select
lbl_Exit:
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 06-17-2015, 01:40 PM
cikanoz87 cikanoz87 is offline How to replace a letter to random letter with different color? Windows 7 32bit How to replace a letter to random letter with different color? Office 2007
Novice
How to replace a letter to random letter with different color?
 
Join Date: Jun 2015
Posts: 4
cikanoz87 is on a distinguished road
Default

Dear Mr. Macropod and Mr. Graham Mayor, thank you vey much for your fast reply and help. I will try to use the script first.
Reply With Quote
  #5  
Old 06-18-2015, 12:11 AM
cikanoz87 cikanoz87 is offline How to replace a letter to random letter with different color? Windows 7 32bit How to replace a letter to random letter with different color? Office 2007
Novice
How to replace a letter to random letter with different color?
 
Join Date: Jun 2015
Posts: 4
cikanoz87 is on a distinguished road
Default

This is my first time using macro, and your script works like charm. However, can I replace the symbols too? Like comma (,), space ( ) and others; and to more character other than alphabet. For example:

Replace space ( ) to random
"Mama gave me an apple" to
"Mama$gavermeдan2apple"

I'm managed to choose the color by replace the wdred to ie: RGB(123,123,123)

Sorry a lot for not request the right thing in the first place, and for request too much.
Thank you.
Reply With Quote
  #6  
Old 06-18-2015, 02:25 AM
gmayor's Avatar
gmayor gmayor is offline How to replace a letter to random letter with different color? Windows 7 64bit How to replace a letter to random letter with different color? Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Change
Code:
    If Len(strChar) > 1 Or Not IsLetter(asc(strChar)) Then
        MsgBox "Enter a single character from the ranges A-Z or a-z only", vbCritical
        GoTo Start
    End If
to
Code:
    If Len(strChar) > 1 Then
        MsgBox "Enter a single character only", vbCritical
        GoTo Start
    End If
and the IsLetter function is no longer required
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 06-18-2015, 06:37 PM
cikanoz87 cikanoz87 is offline How to replace a letter to random letter with different color? Windows 7 32bit How to replace a letter to random letter with different color? Office 2007
Novice
How to replace a letter to random letter with different color?
 
Join Date: Jun 2015
Posts: 4
cikanoz87 is on a distinguished road
Default

Thank you Mr. Mayor, in addition on top script, the new one just change the color if I choose to replace the symbol. However, it was good enough for me. Thank you, I will buy you a cup of coffee from your website later.
Reply With Quote
  #8  
Old 06-18-2015, 09:43 PM
gmayor's Avatar
gmayor gmayor is offline How to replace a letter to random letter with different color? Windows 7 64bit How to replace a letter to random letter with different color? Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You are right, it does. I had forgotten to include the additional characters in the RandomLetter macro
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
font color, random, replace all

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i get the letter in the centre rich_cirillo Word 3 03-09-2014 06:25 PM
How to replace a letter to random letter with different color? Find and replace with a macro, problem with letter case garcanrya Word VBA 2 01-10-2014 05:40 AM
How to replace a letter to random letter with different color? every letter different color skan Word VBA 8 03-28-2013 04:16 AM
How to replace a letter to random letter with different color? Business letter MK_Huef Word 1 03-27-2012 03:27 AM
How to replace a letter to random letter with different color? Replace is capitalizing the first letter of the first word Beachhouse Word 1 02-07-2012 03:36 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:34 AM.


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