PDA

View Full Version : Solved: New find and replace from a document



Pasquale
11-09-2005, 05:36 AM
Exscuse me I repost a thread
Hallo I need still help.
I have a very long text in a doc. I want replace - in first document - all rows that begin with GRK superscipted with the same rows from a second document.

GRK written in superscripted and a sequence of number 1:1, 1:2, 1:3, 2:1, 2:2.... determine the difference from other rows in first document, in the second document all rows begins with GRK superscripted.
GRK rows are in exact sequence in each documents.

Thanks pasquale

example of first document
GRK Mt 1:1 B?bloj gen?sewj 'Ihso? Cristo? u?o? Dau?d u?o? 'Abra?m.
GRT Mt 1:1 Biblos genese?s I?sou Christou huiou Dauid huiou Abraam.
CEI Mt 1:1 Genealogia di Ges? Cristo figlio di Davide, figlio di Abramo.
NVT Mt 1:1 Genealogia di Ges? Cristo, figlio di Davide, figlio di Abramo.

GRK Mt 1:2 'Abra?m ?g?nnhsen t?n 'Isa?k, 'Isa?k d? ?g?nnhsen t?n 'Iak?b, 'Iak?b d? ?g?nnhsen t?n 'Io?dan ka? to?j ?delfo?j a?to?,
GRT Mt 1:2 Abraam egenn?sen ton Isaak, Isaak de egenn?sen ton Iak?b, Iak?b de egenn?sen ton Ioudan kai tous adelphous autou,
CEI Mt 1:2 Abramo gener? Isacco, Isacco gener? Giacobbe, Giacobbe gener? Giuda e i suoi fratelli,
NVT Mt 1:2 Abramo gener? Isacco; Isacco gener? Giacobbe; Giacobbe gener? Giuda e i suoi fratelli;

example of second document
GRK Mt 1:1 B?bloj gen?sewj 'Ihso? Cristo? u?o? Dau?d u?o? 'Abra?m.
GRK Mt 1:2 'Abra?m ?g?nnhsen t?n 'Isa?k, 'Isa?k d? ?g?nnhsen t?n 'Iak?b, 'Iak?b d? ?g?nnhsen t?n 'Io?dan ka? to?j ?delfo?j a?to?,
GRK Mt 1:3 'Io?daj d? ?g?nnhsen t?n F?rej ka? t?n Z?ra ?k t?j Qam?r, F?rej d? ?g?nnhsen t?n `Esr?m, `Esr?m d? ?g?nnhsen t?n 'Ar?m,
GRK Mt 1:4 'Ar?m d? ?g?nnhsen t?n 'Aminad?b, 'Aminad?b d? ?g?nnhsen t?n Naass?n, Naass?n d? ?g?nnhsen t?n Salm?n,
GRK Mt 1:5 Salm?n d? ?g?nnhsen t?n B?ej ?k t?j `Rac?b, B?ej d? ?g?nnhsen t?n 'Iwb?d ?k t?j `Ro?q, 'Iwb?d d? ?g?nnhsen t?n 'Iessa?,


Option Explicit
Sub Greeks()
Dim Doc1 As Document, Doc2 As Document
Dim RegEx As Object
Dim RegO1 As Object, RegO2 As Object, i As Long
Set Doc1 = Documents("FirstDocument")
Set Doc2 = Documents("SecondDocument")

Set RegEx = CreateObject("vbscript.regexp")
RegEx.Global = True
RegEx.Pattern = "(GRK\s{1}Mt\s{1})([0-9]{1,3}:[0-9]{1,3})(.*?\r)"
Set RegO1 = RegEx.Execute(Doc1.Content.Text)
Set RegO2 = RegEx.Execute(Doc2.Content.Text)
'This code would need modding if the ordering system was different between docs
Application.ScreenUpdating = False
For i = 1 To RegO1.Count
If RegO1(i - 1).submatches(1) = RegO2(i - 1).submatches(1) Then
With Doc1.Content.Find
.Text = RegO1(i - 1)
.Replacement.Text = RegO2(i - 1)
.Execute Replace:=wdReplaceOne
End With
End If
Next
Application.ScreenUpdating = True
End Sub

This VBA macro don't work.

Helpme please.:dunno :dunno

brettdj
11-09-2005, 05:40 AM
Hi Pasquale - didn't it work last time?

Cheers

Dave

Pasquale
11-09-2005, 05:46 AM
Hi, brettdj, with greek characters it is difficult to Know if works immediately.
It work only for some rows and not for all rows.
The number of GRK Mt 1:1, 1:2, after, 2:1, 2:2, after.... 10:1, 10:2,......11:1 ......

The replace worked till 10:25 and stop in replacing.



Attention:
In the First document:
(Font Times New Roman) GRK Mt 1:1 (Font Bwgrkl).................
(Font Times New Roman) GRT Mt 1:1..............
........

In the secon document:
(Font Times New Roman) GRK Mt 1:1 (Font Greek)...........

Pasquale
Thanks Pasquale.

brettdj
11-09-2005, 06:20 AM
Can you please post the docs (both before the code was run, and then after) and highlight where it stopped working

Cheers

Dave

Pasquale
11-09-2005, 07:09 AM
To day not work nothing.
Nothing message of errors.
I don't know.
Thanks

Pasquale

Pasquale
11-10-2005, 04:48 AM
Hallo,
RegEx is VBA or VBscript?????
I don't have VBSscript.

Pasquale

brettdj
11-10-2005, 04:57 AM
Do you get an error message when running it?

You should have a file called vbscript.dll in your system directory - can you find it?

Cheers

Dave

Pasquale
11-10-2005, 05:19 AM
Hi, brettdj, I have this file in sistem32 dir.
perhaps Italian office 2003 have different command, or expression?


'This code would need modding if the ordering system was different between docs

Perahps I must modding something?
Pasquale

brettdj
11-10-2005, 05:20 AM
So - do you get an error message on

Set RegEx = CreateObject("vbscript.regexp")

Pasquale
11-10-2005, 05:24 AM
No when I run the macro , it is in working, and after the documents is the same. No change
pasquale

Pasquale
11-10-2005, 05:34 AM
Hi brettdj,
Here
Set Doc1 = Documents("FirstDocument")
Set Doc2 = Documents("SecondDocument")

I write

Set Doc1 = Documents("Books.doc")
Set Doc2 = Documents("Notes.doc")

Here

RegEx.Pattern = "(GRK\s{1}Mt\s{1})([0-9]{1,3}:[0-9]{1,3})(.*?\r)"


I write


RegEx.Pattern = "(GRK\s{1}Mt\s{1})([0-9]{1;3}:[0-9]{1;3})(.*?\r)"


In Italian VBA "," is ";"

Pasquale

Pasquale
11-10-2005, 05:36 AM
Perahaps , the problem is GRK superscripted????

brettdj
11-10-2005, 07:51 AM
Can you please post the docs in a zip file (both filesbefore the code was run, and then both after) and highlight where it stopped working

Pasquale
11-10-2005, 09:54 AM
Hi Brett, there is no change after run macro,
nothing change.
The documents doesn't change.
The text is the same before and after run the macro.
Exscuse me for bad English.
Pasquale

Pasquale
11-10-2005, 12:04 PM
Hi brett This macro work for the first row,


Sub interlineare()

'

' interlineare Macro

' Macro registrata il 10/11/05 da ???????o??

'

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

With Selection.Find

.Text = "GRK Mt [0-9]{1;3}:[0-9]{1;3} *^13"

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = True

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute

Windows(1).Activate

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

With Selection.Find

.Text = "GRK Mt [0-9]{1;3}:[0-9]{1;3} *^13"

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = True

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute

Selection.Copy

Windows(2).Activate

Selection.Paste



How to do for working for all rows?

Pasquale

brettdj
11-10-2005, 05:31 PM
This macro isn't my code.

Are the documents the same as the one you posted in the other thread?

Pasquale
11-10-2005, 11:04 PM
NO they are differents. In the other thread there are two different documents.

This macro works only for one row.

Sub Interlineare()
'
' Interlineare Macro
' Macro registrata il 10/11/05 da ????????????????????
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "GRK Mt [0-9]{1;3}:[0-9]{1;3} *^13"
.Replacement.Text = "GRK"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Copy
Windows(2).Activate
Selection.Find.ClearFormatting
With Selection.Find
.Text = "GRK Mt [0-9]{1;3}:[0-9]{1;3} *^13"
.Replacement.Text = "GRK"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Paste
Windows(1).Activate
EndSub

brettdj
11-12-2005, 04:43 AM
Pasqual,

I ran my code over your two documents, but first I changed the first four lines and the last line of Doc 2 to make it easier to see if it worked

All the changes were made to Doc 1 correctly, see attached files

I think that you rating this thread as "bad" was a little premature ...

Dave

Pasquale
11-12-2005, 07:01 AM
Hi Brett,
Thanks very much and exscuse me.

Pasquale:bow: