#1
|
|||
|
|||
How to find&replace several items at once?
Hi! I need to change text from one font to another but not all the symbols match up in the fonts coding. So I would like to use Find&Replace to find all the symbols I want to change and replace them at once. Is that possible? |
#2
|
||||
|
||||
Yes, but you'd need to know the character codes of the characters to be replaced. If you know that, you could use a wildcard Find/Replace, where:
Find = [^0191^0233] Replace = ^& where the numbers following the ^ characters are the 4-digit character codes (for ¿ and ß in the above example) and you specify both the Find and Replace fonts. If the result of doing this is that you'll have words etc. using a mix of fonts, this is not a good solution (IMHO); you'd do better to use a font that does support all of the characters in use.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
How do you find out character codes? And in the Replace field how do you specify what exactly you want to replace? I didn't understand that part from your example.
Fonts won't be mixed since I just need one font and just to change incorrect characters with the proper ones from the same font character map. Just some remapping has to be done. |
#4
|
||||
|
||||
OK, since they're not from different fonts, you can't use the Replace expression. A different approach would be needed. That said, you should be able to find the character codes by selecting a given character and using Insert|Symbol to find its value. Alternatively, if you're willing to Find/Replace them one at a time, simply copy & paste a character into the Find box and type the replacement character into the Replace box.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I'm sorry, I didn't express myself properly. The symbols I want to change are from different fonts. They are the same symbols but font mappings are different. Anyway, I tried your advice, typing character codes in the Find field but word cannot find them!
Btw. When I just copy/paste a symbol I want to replace and then change the font and put the required symbol in Replace field it works ok. I just don't want to change all the symbols one-by-one rather making a string to change them all at once. If you don't mind and have a little time, I added text examples and those 2 fonts I'm using. There are two fonts, Tamalten and Balaram. Input text is in Tamalten and I need it to be in Balaram, with the same symbols as in tamalten font. |
#6
|
||||
|
||||
OK, now that I can see what you have, you could use a macro like:
Code:
Sub BulkFindReplace() Application.ScreenUpdating = False Dim FList As String, RList As String, j As Long FList = "¸|î|å|?|®|ß" RList = "Ç|é|ä|ë|å|ñ" With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Format = False .Forward = True .MatchCase = True .MatchWholeWord = False 'Process each item from the Find/Replace Lists For j = 0 To UBound(Split(FList, "|")) .Text = Split(FList, "|")(j) .Replacement.Text = Split(RList, "|")(j) .Execute Replace:=wdReplaceAll Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Wow! Thanks man! That's what I was looking for. It works... but there is a problem. Somehow when I insert the necessary characters into the macro it will display question marks instead. Can I replace the symbols with character codes? If so then how?
|
#8
|
||||
|
||||
I simply copied the characters from your documents into the macro. If you have characters that won't copy that way, you'll need to provide another document, preferably with just those characters and their replacements, so I can take a look at it.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Something is wrong here. THe macro is working. When I paste those sankrit diacritic symbols, they appear as question marks, the same symbols that you were pasting. So then I tried to paste usual characters and that is fine. But the replace field I left the same as you already made. But instead of changing usual letters into those characters, word is putting russian letters instead! So something is wrong with languages here. I do have russian installed on computer, but so what? The word I use is in English although this should have nothing to do with that. And I tried two versions of Word, 2010 and 1013. Same problem.
Btw. I changed macro font into Tamaten, the first font I want to change. Still, when pasting a symbol in the same font it appears as a question mark. |
#10
|
||||
|
||||
As I said in my last post, you'll need to provide another document, preferably with just those characters and their replacements, so I can take a look at it. You can attach a document to a post via the paperclip symbol on the 'Go Advanced' tab.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Ok, here are the symbols.
|
#12
|
||||
|
||||
Try:
Code:
Sub BulkFindReplace() Application.ScreenUpdating = False Dim FList As String| RList As String| j As Long FList = "Å|å|®|ñ|ß|" & ChrW(&H222B) & "|Â|µ|Í|¸|" & ChrW(&H3A9) & "|È|î|Ê|†|õ|" & ChrW(&H2D9) & "|¨|" & ChrW(&H2202) RList = "Ä|ä|å|ï|ñ|ë|À|à|Ñ|Ç|ç|É|é|Ö|ö|ì|ù|Ü|ò" With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Format = False .Forward = True .MatchCase = True .MatchWholeWord = False 'Process each word from the Find/Replace Lists For j = 0 To UBound(Split(FList| "|")) .Text = Split(FList| "|")(j) .Replacement.Text = Split(RList| "|")(j) .Execute Replace:=wdReplaceAll Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Bingo!
It works and aslo I understood why I didn't see the symbols. I had the language for non-unicode programs set to Russian. I need it to display russian characters in some text files and programs. So when it is in English, then everything works. It is a nuisance to switch the languages, but I can do it once in a while and then do a batch conversion of texts. One small thing is still to be corrected. I tried myself but couldn't do it. The Û one has to be added. And is it possible that at the end of the macro it will keep displaying Balaram font? Somehow I have to change it again into balarama at the end. |
#14
|
||||
|
||||
For the 'Û', add:
& "|Û" to the FList definition and add: |x to the RList definition, where 'x' is the replacement character (you don't seem to have specified it). As for the font, the macro doesn't make any changes - it leaves everything as it found it. If the issue is that the replacement characters are in the wrong font, insert: .Replacement.Font.Name = "Balaram" after: .MatchWholeWord = False and change: .Format = False to: .Format = True
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
Thank you very very much, now everything works perfectly!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I find and replace multiple items at once? | redzan | Word VBA | 1 | 05-16-2013 08:25 AM |
Find and Replace | kjxavier | Word | 1 | 03-31-2012 06:57 PM |
Bad view when using Find and Find & Replace - Word places found string on top line | paulkaye | Word | 4 | 12-06-2011 11:05 PM |
Is there a way to use "find/replace" to find italics words? | slayda | Word | 3 | 09-14-2011 02:16 PM |
Help with find and replace or query and replace | shabbaranks | Excel | 4 | 03-19-2011 08:38 AM |