Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2018, 01:41 PM
kvnrao kvnrao is offline multiple find and replace in vba for special words Windows 10 multiple find and replace in vba for special words Office 2016
Novice
multiple find and replace in vba for special words
 
Join Date: Nov 2018
Posts: 4
kvnrao is on a distinguished road
Default multiple find and replace in vba for special words

I have the following vba macro in msoffice word, where individual programs are written for each special word. How to write a combined and comprehensive program.
Sub Macro1()
'
' Macro1 Macro
'
'
Selection.HomeKey

With Selection.Find
.Text = ChrW(257)
.Replacement.Text = "A"
.Forward = True
.Wrap = wdFindContinue
End With


Selection.Find.Execute Replace:=wdReplaceAll

' Selection.HomeKey
With Selection.Find
.Text = ChrW(275)
.Replacement.Text = "E"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = ChrW(299)
.Replacement.Text = "I"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = ChrW(333)
.Replacement.Text = "O"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = ChrW(363)
.Replacement.Text = "U"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll

End Sub
Reply With Quote
  #2  
Old 11-01-2018, 05:04 PM
Guessed's Avatar
Guessed Guessed is offline multiple find and replace in vba for special words Windows 10 multiple find and replace in vba for special words Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,990
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

I'm not sure on what exactly you are expecting so all we can do is simplify what your code is already doing to make it more straightforward. This won't work any differently to what you already had.
Code:
Sub Macro1()
  With Selection.Find
    .Wrap = wdFindContinue

    .Text = ChrW(257)
    .Replacement.Text = "A"
    .Execute Replace:=wdReplaceAll

    .Text = ChrW(275)
    .Replacement.Text = "E"
    .Execute Replace:=wdReplaceAll

    .Text = ChrW(299)
    .Replacement.Text = "I"
    .Execute Replace:=wdReplaceAll

    .Text = ChrW(333)
    .Replacement.Text = "O"
    .Execute Replace:=wdReplaceAll

    .Text = ChrW(363)
    .Replacement.Text = "U"
    .Execute Replace:=wdReplaceAll
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-01-2018, 07:40 PM
kvnrao kvnrao is offline multiple find and replace in vba for special words Windows 10 multiple find and replace in vba for special words Office 2016
Novice
multiple find and replace in vba for special words
 
Join Date: Nov 2018
Posts: 4
kvnrao is on a distinguished road
Default Find & Replace multiple

Thank you for the response. I would like the program to be completed just in few lines.
if we can arrange the text to be replaced in one line and replacing text in another line, it shall be fine.
Ex.
text to be replaced (chaW(257), chaW(275),...)
replacement text ( A, E,...)
Reply With Quote
  #4  
Old 11-01-2018, 08:58 PM
macropod's Avatar
macropod macropod is offline multiple find and replace in vba for special words Windows 7 64bit multiple find and replace in vba for special words 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

How about reading, for example: https://www.msofficeforums.com/word-...html#post46365
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-01-2018, 08:58 PM
Guessed's Avatar
Guessed Guessed is offline multiple find and replace in vba for special words Windows 10 multiple find and replace in vba for special words Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,990
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

Which sounds like a study task...

So how about you do some research on VBA arrays and looping through arrays. Post back with some evidence that you've made an attempt at solving this yourself and we can help you refine it.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #6  
Old 11-02-2018, 11:15 AM
kvnrao kvnrao is offline multiple find and replace in vba for special words Windows 10 multiple find and replace in vba for special words Office 2016
Novice
multiple find and replace in vba for special words
 
Join Date: Nov 2018
Posts: 4
kvnrao is on a distinguished road
Default Find Replace

Thank you all, for your proactive suggestions. I could solve it taking reference to your ideas.
Solved program is like this

Sub FiRe()
Application.ScreenUpdating = False
Dim Tbl As Table, FndList, RepList, i As Long
FndList = Array(ChrW(257), ChrW(275), ChrW(299), ChrW(333), ChrW(363))
RepList = Array("A", "E", "I", "O", "U")
Selection.HomeKey Unit:=wdStory
With ActiveDocument

With Selection.Find
For i = 0 To UBound(FndList)
.Text = FndList(i)
.Replacement.Text = RepList(i)
.Execute Replace:=wdReplaceAll
Next
End With
Application.ScreenUpdating = True
End With

End Sub

Thank you all once again
Reply With Quote
  #7  
Old 11-02-2018, 05:59 PM
Guessed's Avatar
Guessed Guessed is offline multiple find and replace in vba for special words Windows 10 multiple find and replace in vba for special words Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,990
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 tidy up the code a bit more. Note the differences with this version.
Code:
Sub FiRe()
  Dim FndList() As String, RepList() As String, i As Long
  Application.ScreenUpdating = False
  FndList = Split("257,275,299,333,363", ",")
  RepList = Split("A,E,I,O,U", ",")
  With ActiveDocument.Range.Find
    .Wrap = wdFindContinue
    For i = 0 To UBound(FndList)
      .Text = ChrW(FndList(i))
      .Replacement.Text = RepList(i)
      .Execute Replace:=wdReplaceAll
    Next
  End With
  Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 11-02-2018, 06:28 PM
kvnrao kvnrao is offline multiple find and replace in vba for special words Windows 10 multiple find and replace in vba for special words Office 2016
Novice
multiple find and replace in vba for special words
 
Join Date: Nov 2018
Posts: 4
kvnrao is on a distinguished road
Default Find & Replace

Oh! beautiful and more simple
Thanks once again
Reply With Quote
Reply

Tags
find and replace, vba in microsoft word, vba in word



Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple find and replace in vba for special words VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Kalü Word VBA 22 04-24-2018 05:35 AM
multiple find and replace in vba for special words Find and replace mutiple spaces between lowercase words only Dave T Word VBA 2 07-16-2015 11:23 PM
multiple find and replace in vba for special words how to replace to words with multiple formats cdk270 Word 1 07-16-2015 01:56 AM
multiple find and replace in vba for special words Highlight and then replace multiple words redhin Word VBA 5 03-05-2013 05:42 AM
multiple find and replace in vba for special words Find & Replace: substitute red-coloured words with underscores tinfanide Word 2 10-06-2012 11:04 PM

Other Forums: Access Forums

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