Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2016, 02:55 PM
djpemberton djpemberton is offline Find and Replace Macro Need Windows 7 32bit Find and Replace Macro Need Office 2010 32bit
Novice
Find and Replace Macro Need
 
Join Date: Mar 2014
Posts: 2
djpemberton is on a distinguished road
Default Find and Replace Macro Need

I am formating a new Bible translation for a certain software.

The original document looks like this:

Code:
[[@Bible:mat 1:1]][[1>>Bible:mat 1:1]] ईसा मसीह बिन दाऊद बिन इब्राहीम का नसबनामा : 

[[@Bible:mat 1:2]][[2>>Bible:mat 1:2]] इब्राहीम इस्हाक़ का बाप था, इस्हाक़ याक़ूब का बाप और याक़ूब यहूदा और उस के भाइयों का बाप। 
[[@Bible:mat 1:3]][[3>>Bible:mat 1:3]] यहूदा के दो बेटे फ़ारस और ज़ारह थे (उन की माँ तमर थी)। फ़ारस हस्रोन का बाप और हस्रोन राम का बाप था। 
[[@Bible:mat 1:4]][[4>>Bible:mat 1:4]] राम अम्मीनदाब का बाप, अम्मीनदाब नह्सोन का बाप और नह्सोन सल्मोन का बाप था। 
[[@Bible:mat 1:5]][[5>>Bible:mat 1:5]] सल्मोन बोअज़ का बाप था (बोअज़ की माँ राहब थी)। बोअज़ ओबेद का बाप था (ओबेद की माँ रूत थी)। ओबेद यस्सी का बाप और 
[[@Bible:mat 1:6]][[6>>Bible:mat 1:6]] यस्सी दाऊद बादशाह का बाप था।
I need to add {{field-off:Bible}} and {{field-on:Bible}} markers at specific places around each verse, resulting in this:



Code:
[[@Bible:Matt 1:1]][[1>>Bible:Matt 1:1]]{{field-on:Bible}} ईसा मसीह बिन दाऊद बिन इब्राहीम का नसबनामा :{{field-off:Bible}}
 
[[@Bible:Matt 1:2]][[2>>Bible:Matt 1:2]]{{field-on:Bible}} इब्राहीम इस्हाक़ का बाप था, इस्हाक़ याक़ूब का बाप और याक़ूब यहूदा और उस के भाइयों का बाप।{{field-off:Bible}}
[[@Bible:Matt 1:3]][[3>>Bible:Matt 1:3]]{{field-on:Bible}} यहूदा के दो बेटे फ़ारस और ज़ारह थे (उन की माँ तमर थी)। फ़ारस हस्रोन का बाप और हस्रोन राम का बाप था।{{field-off:Bible}}
[[@Bible:Matt 1:4]][[4>>Bible:Matt 1:4]]{{field-on:Bible}} राम अम्मीनदाब का बाप, अम्मीनदाब नह्सोन का बाप और नह्सोन सल्मोन का बाप था।{{field-off:Bible}}
[[@Bible:Matt 1:5]][[5>>Bible:Matt 1:5]]{{field-on:Bible}} सल्मोन बोअज़ का बाप था (बोअज़ की माँ राहब थी)। बोअज़ ओबेद का बाप था (ओबेद की माँ रूत थी)। ओबेद यस्सी का बाप और{{field-off:Bible}}
[[@Bible:Matt 1:6]][[6>>Bible:Matt 1:6]]{{field-on:Bible}} यस्सी दाऊद बादशाह का बाप था।
  
दाऊद सुलैमान का बाप था (सुलैमान की माँ पहले ऊरिय्याह की बीवी थी){{field-off:Bible}}
Here is a Macro that I had created for it a while back:

Code:
Sub LogosField()
'
' LogosField Macro
'
'
With ActiveDocument.Content.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "\[\[*\]\]\[\[*\]\]"
  .Replacement.Text = "{{field-off:Bible}}^&{{field-on:Bible}}"
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchWildcards = True
  .Execute Replace:=wdReplaceAll
End With
End Sub
It gets close, but results in this:

Code:
{{field-off:Bible}}[[@Bible:mat 1:1]][[1>>Bible:mat 1:1]]{{field-on:Bible}} ईसा मसीह बिन दाऊद बिन इब्राहीम का नसबनामा :

{{field-off:Bible}}[[@Bible:mat 1:2]][[2>>Bible:mat 1:2]]{{field-on:Bible}} इब्राहीम इस्हाक़ का बाप था, इस्हाक़ याक़ूब का बाप और याक़ूब यहूदा और उस के भाइयों का बाप।
{{field-off:Bible}}[[@Bible:mat 1:3]][[3>>Bible:mat 1:3]]{{field-on:Bible}} यहूदा के दो बेटे फ़ारस और ज़ारह थे (उन की माँ तमर थी)। फ़ारस हस्रोन का बाप और हस्रोन राम का बाप था।
{{field-off:Bible}}[[@Bible:mat 1:4]][[4>>Bible:mat 1:4]]{{field-on:Bible}} राम अम्मीनदाब का बाप, अम्मीनदाब नह्सोन का बाप और नह्सोन सल्मोन का बाप था।
{{field-off:Bible}}[[@Bible:mat 1:5]][[5>>Bible:mat 1:5]]{{field-on:Bible}} सल्मोन बोअज़ का बाप था (बोअज़ की माँ राहब थी)। बोअज़ ओबेद का बाप था (ओबेद की माँ रूत थी)। ओबेद यस्सी का बाप और
{{field-off:Bible}}[[@Bible:mat 1:6]][[6>>Bible:mat 1:6]]{{field-on:Bible}} यस्सी दाऊद बादशाह का बाप था।

दाऊद सुलैमान का बाप था (सुलैमान की माँ पहले ऊरिय्याह की बीवी थी)।
{{field-off:Bible}}
As you can see, the "field-on" markers are correctly placed, but the "field-off" markers come just before the "[[@Bible . . ." instead of just after the last text before "[[@Bible . . ."

Any suggestions?
Reply With Quote
  #2  
Old 05-04-2016, 04:22 PM
macropod's Avatar
macropod macropod is offline Find and Replace Macro Need Windows 7 64bit Find and Replace Macro Need 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

You don't need a macro for this - it can be done with a wildcard Find/Replace, where:
Find = (\]\])([!^13\]]@)^13
Replace = \1{{field-on:Bible}}\2{{field-off:Bible}}^p
That said, you could simply replace your existing Find/Replace parameters with the above:
Code:
Sub LogosField()
'
' LogosField Macro
'
Application.ScreenUpdating = False
With ActiveDocument.Content.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Forward = True
  .Format = False
  .Wrap = wdFindContinue
  .MatchWildcards = True
  .Text = "(\]\])([!^13\]]@)^13"
  .Replacement.Text = "\1{{field-on:Bible}}\2{{field-off:Bible}}^p"
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-04-2016, 07:53 PM
djpemberton djpemberton is offline Find and Replace Macro Need Windows 7 32bit Find and Replace Macro Need Office 2010 32bit
Novice
Find and Replace Macro Need
 
Join Date: Mar 2014
Posts: 2
djpemberton is on a distinguished road
Default

That seemed to work beautifully! Thanks! I'll have to analyze it a bit to learn exactly what you did.
Reply With Quote
Reply

Tags
macro, macro find and replace

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Short Macro-Find and Replace rsrasc Word VBA 2 11-10-2014 05:03 PM
Find and Replace Macro Need Find and Replace Macro amparete13 PowerPoint 3 03-11-2014 05:29 AM
Find and Replace Macro Need Is the following too complex for find/replace macro? bertietheblue Word VBA 12 11-04-2013 05:35 PM
macro or find/replace JamesVenhaus Word 2 02-27-2012 03:34 PM
Find and Replace Macro - A Better Way Tribos Word VBA 0 10-08-2008 03:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:48 PM.


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