Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2020, 11:30 PM
djced djced is offline Find and replace issue Windows XP Find and replace issue Office 2007
Novice
Find and replace issue
 
Join Date: Jan 2020
Posts: 5
djced is on a distinguished road
Question Find and replace issue

Hi Dear Experts

Few letters are different in other fonts
So, I've problems in changing to new fonts
I use the following code (copied from internet) to solve this. Case specific.

Code:
Private Sub Test1()
         
  Dim strFindText As String
  Dim strReplaceText As String
  Dim nSplitItem As Long
   
  Application.ScreenUpdating = False

  ' Enter items to be replaces and new ones.
  strFindText = InputBox("Enter items to be found here,seperated by comma: ", "Items to be found") 
 'b,n,N,O,G,&,+,`,o,A,T,%,[,+,g{ - Find texts
  strReplaceText = InputBox("Enter new items here, seperated by comma: ", "New items")
  'o,b,n,G,g[,U:,g{,+,H,a[,t[,K:,$,G:,* - Replace texts
 
  nSplitItem = UBound(Split(strFindText, ","))

  ' Find each item and replace it with new one respectively.
  For nSplitItem = 0 To nSplitItem
    With Selection
      .HomeKey Unit:=wdStory
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = Split(b, n, G, o, a, T, ",")(nSplitItem)
        .Replacement.Text = Split(o, b, n, G, H, ",")(nSplitItem)
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
      End With
    Selection.Find.Execute Replace:=wdReplaceAll
  End With
Next nSplitItem

  Application.ScreenUpdating = True

End Sub

1. I wish to remove input box and use permanent text string in place of that. But some are special characters like (, ), [, ], +, *, {, }
2. If the same is restricted to particular font (say 'xxx') and to particular selection
3. also note that few letters are interchanging like b,o,n etc (so it need to be changed to someother letter before final change



Thanking you!
Jai
Reply With Quote
  #2  
Old 01-28-2020, 11:37 PM
macropod's Avatar
macropod macropod is offline Find and replace issue Windows 7 64bit Find and replace issue 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

See, for example: https://www.msofficeforums.com/55215-post6.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-29-2020, 12:00 AM
djced djced is offline Find and replace issue Windows XP Find and replace issue Office 2007
Novice
Find and replace issue
 
Join Date: Jan 2020
Posts: 5
djced is on a distinguished road
Smile Thanks

Really fast reply that i haven't expected.... Thanks.

Let me check Sir

Reply With Quote
  #4  
Old 01-29-2020, 12:50 AM
djced djced is offline Find and replace issue Windows XP Find and replace issue Office 2007
Novice
Find and replace issue
 
Join Date: Jan 2020
Posts: 5
djced is on a distinguished road
Default

Sir
Works fine.
But I have the following issues
i am replacing
Quote:
b,n,N,O,G,&,+,`,o,A,T,%,[,+,g{
into
Quote:
o,b,n,G,g[,U:,g{,+,H,a[,t[,K:,$,G:,*
1. for the first instance 'b' changes to 'o' ('o' change to 'H' pending)
2. later when 'o' changes to 'H' all the first changed 'o' also changes along with the new change
3. So, 'b' changes to 'o' and then to 'H'

likewise other letters
Possible solution
Can the change be effected on 1. particular font 2. text portion in selection
and the changed letter to another font namely 'Arial'

Jai
Reply With Quote
  #5  
Old 01-29-2020, 01:05 AM
macropod's Avatar
macropod macropod is offline Find and replace issue Windows 7 64bit Find and replace issue 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

If you don't want some replaced terms to be replaced by later F/R operations, then you need to ensure the order of the various F/R expressions are listed in the correct order.

If you only want to process whatever is selected, change:
With ActiveDocument.Range.Find
to:
With Selection.Range.Find

If you only want to process a particular font (Arial), change:
.Format = False
to:
.Format = True
.Font.Name = "Arial"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 01-29-2020, 02:25 PM
Guessed's Avatar
Guessed Guessed is offline Find and replace issue Windows 10 Find and replace issue Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can also avoid the order of replacement issue by using the fact that you are wanting to restrict your find to a particular typeface.

If you replaced the found Arial character with a different character in a different typeface then the subsequent searches would not find the new character. If it all has to end up as Arial then pick a typeface not in use anywhere and then run a final search and replace to swap anything in that typeface back to Arial.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
find, font, replace all

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace issue Find and replace issue nrsmd Word 3 06-05-2015 03:20 PM
Find and replace issue Issue with Find/Replace with Notes cheech1981 Word 3 08-31-2013 11:22 PM
Find and replace issue Find and Replace Format macro issue Jack Word VBA 2 12-12-2012 09:24 PM
Find and replace issue Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Find & Replace Insert Issue mipacker Word 0 02-18-2009 08:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:10 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