View Full Version : Solved: MergeText
Pasquale
07-26-2005, 01:32 AM
I mustl merge two files - A main file (containing Bible text excerpts) and an End Notes file (see attached sample files "sample 3 books bible.doc" and "sample end notes.doc"). The following modifications for the end notes file:
1. Square brackets to be replaced with curly brackets
2. The end curly bracket to be moved to the end of the paragraph..
3. Replace << and >> with "
The supplied workbook, books of the bible.xls, will be used to match and replace book names.
Standard formatting is required in the reference documents. For example only one paragraph return between lines. Whichever, it must be the same throughout the document.
Example:
Bible text:
Phm 1:2 alla sorella Appia, ad Archippo nostro compagno d' armi e alla comunit? che si raduna nella tua casa,
End note text (modified):
{Fm 1,2 alla sorella Appia: varianti: ?sorella diletta?, ?nostra diletta?, ?nostra sorella diletta?.}
Final text (merged):
Phm 1:2 alla sorella Appia, ad Archippo nostro compagno d' armi e alla comunit? che si raduna nella tua casa:{Fm 1,2 alla sorella Appia: varianti: ?sorella diletta?, ?nostra diletta?, ?nostra sorella diletta?.}
Thanks fot attention:help
fumei
07-26-2005, 07:42 AM
Sorry...but what is the question? Are you having a problem with something? You did not ask anything. You "must" merge two files. Yes...and....?????
Pasquale
07-26-2005, 07:47 AM
Exscuse me for bad English.
Hallo the problem is:
I must merge the text of the two files, It is two long file (1-whole bible text) to merge with a long end-notes file, and the end-notes must be put at the end of related bible verse (see example).
Thanks for attention
pasquale
xCav8r
07-26-2005, 08:46 AM
Pasquale, ho capito piu' o menu quello che hai scritto in inglese. Cmq, il fuso orario che hai scelto per il foro mi sembra sbagliato. Dice GMT - 8, il fuso orario di California. Il tuo dovrebbe essere GMT + 1, no? ;)
Looking at your examples...
xCav8r
07-26-2005, 09:20 AM
I think I know what he wants to do. Maybe someone can help him with code for the second part of this.
1. A few find and replaces in "sample end notes.doc." These can be done manually (CTRL+H) and I don't see why they need to be done in VBA. If I'm missing the point, here's something Pasquale can use.
Sub ReplaceThisWithThat(strReplaceMe As String, strReplaceWithThis As String)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = strReplaceMe
.Replacement.Text = strReplaceWithThis
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
2. He wants to loop through each paragraph in the bible excerpts file and conditionally append the corresponding lines from the end notes file to the same paragraph. Conditionally means when it exists. There are not end notes for every line.
Pasquale, is what I said correct?
MOS MASTER
07-26-2005, 09:55 AM
Pasquale, ho capito piu' o menu quello che hai scritto in inglese. Cmq, il fuso orario che hai scelto per il foro mi sembra sbagliato. Dice GMT - 8, il fuso orario di California. Il tuo dovrebbe essere GMT + 1, no? ;)
Looking at your examples...
Well Marco aren't we showing of....hidden talent? :yes
xCav8r
07-26-2005, 10:00 AM
Who me? I was temporarily possessed. :eek:
MOS MASTER
07-26-2005, 10:05 AM
Who me? I was temporarily possessed. :eek:
Indeed you have that a lot these days! :devil:
xCav8r
07-26-2005, 10:07 AM
Indeed, but why is it always by time zone conscious Italians? I think I've got a question coming on for Babydum.
Pasquale
07-26-2005, 04:17 PM
Thanks for VBA codes, and for help.
Yes is the answer at the second question, There are not end notes for every line.
Grazie - Thanks
How change "il fuso orario"?
xCav8r
07-26-2005, 04:33 PM
You can change your time zone by editing your profile. At the top of this page, look for "Quick Links" then select "Edit Options". On the page that comes up, go to the section for Date and Time options. For time zone, choose GMT + 1, then DST (daylight savings time) Correction Option, choose automatically detect. Once that's done, when you see the local time under your name, it should be correct for your local time, and when you mouse over your flag, it should say GMT + 1. Which, if you did it at around the time of this post, should be ~1.30.
Oh, and welcome to VBAX, Pasquale. You write in English well enough, but if you wanted to write in Italian, that would be okay with me. ;)
Hopefully a few other people will offer opinions on how best to accomplish this, but I think you might do the merge easier outside of Word using Excel or Access. You can always put it back into Word when you're done, but the advantage of using Excel or Access would allow you to be to parse up the chapter:verse reference, the text of the chapter:verse, and the endnotes for the chapter:verse. Does that make sense?
Pasquale
07-26-2005, 04:41 PM
Grazie ho cambiato il profilo e il fuso penser? a fare il lavoro con excel.
Buona notte a tutti
Good night
Brandtrock
07-26-2005, 05:00 PM
Hello Pasquale and welcome to VBAX.
Foreign Language Forum (http://www.vbaexpress.com/forum/forumdisplay.php?f=74)
English or Italian is fine here, but our poor other languages forum is feeling lonely. :hi:
Regards,
xCav8r
07-26-2005, 05:02 PM
Actually, I have a bone to pick with the concept of that forum. ;) Think I'll post something multilingual about it. :whip
Brandtrock
07-26-2005, 05:04 PM
Better bone up on my other languages then. :rofl:
Pasquale
07-27-2005, 08:23 AM
Hallo,
How to move The end curly bracket to the end of the paragraph?
Is a long test
thanks I posted the file in excel format in an italian forum for explain better the question
pasquale
fumei
07-27-2005, 09:08 AM
I am not sure what is being asked for here. Move something?
BTW: here is a more efficient way to replace one string with another. You can test using the =rand command to put in testing text.
=rand(4,4) - and press Enter will insert 4 paragraphs each containing 4 sentences of "The quick brown fox jumps over the lazy dog." The code below will replace all "brown" text with "green" text.
Sub ReplaceThisWithThat(sThis As String, sThat As String)
Selection.HomeKey unit:=wdStory
With Selection.Find
.ClearFormatting
Do While (.Execute(findtext:=sThis, Forward:=True, _
Wrap:=wdFindContinue, replacewith:=sThat) = True) _
= True
Loop
End With
End Sub
Sub TryReplace()
ReplaceThisWithThat "brown", "green"
End Sub
Pasquale
07-27-2005, 11:32 AM
Hallo the problem is this
My text to modify is:
{Gen 1:1} Yesterday night ecc
{Gen 1:2} hallo hallo sub marine ecc
I want move } at the and of paragraph.
sample:
{Gen 1:1 Yesterday night ecc}
{Gen 1:2 hallo hallo sub marine ecc}
It is a long long test
ciao
pasquale
xCav8r
07-27-2005, 04:07 PM
Moose, is this easy enough to do with the word objects, or should he move this to excel or access to manipulate these strings? Seems to me it would be more valuable in Access if it were parsed, but that's my opinion. What's yours?
TonyJollans
07-27-2005, 04:43 PM
Hi Pasquale,
You can move your curly brace using Find and Replace ..
Check Use Wildcards
Find Text: \{(*)\}(*)^13
Replace Text: {\1\2}^13
Just hit Replace All
(and record it if you want code)
Pasquale
07-28-2005, 02:29 AM
Hallo the VBA codes is this, but moves only the first }
How to do move all }
Perhaps Loop or DoLoop While
Please complete me the macro under
Thanks
pasquale
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearForm atting
With Selection.Find
.Text = "}"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceOne
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.TypeText Text:="}"
End Sub
TonyJollans
07-28-2005, 03:03 AM
Hi Pasquale,
No need for a loop. This is a single operation but if you want to perform it on multiple files, here is the code as per my previous suggestion ..
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "\{(*)\}(*)^13"
.Replacement.Text = "{\1\2}^13"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Pasquale
07-28-2005, 03:40 AM
Hallo Tony
it is a better better macro
It is OK
for my work
thanks pasquale
TonyJollans
07-28-2005, 03:57 AM
Ok, now for the merging.
The fact that it is in Word doesn't really make much difference; this is a standard two file merge. I will try and post some code later this morning. One question, though. Will the two files be in the same order or will one or both need sorting first?
Pasquale
07-28-2005, 04:19 AM
I have so many files how are the bible books (73 file), Gen, Eso, Lev, Num ecc; and so many files of end-notes, Gen end_notes, Eso end_notes, Lev end_notes ecc ecc.
I can obtain a single file or 73 file, is the same.
What is the better work for a macro?
Attention:
Not all bible verses have related end_notes verse.
Thanks Pasquale
TonyJollans
07-28-2005, 04:43 AM
Let's say you have a document of a single book and a document of notes for a single book - will both be in verse order?
Pasquale
07-28-2005, 05:33 AM
Yes I have a first document of a single book and a second document of notes for a single book - They are both in verse order, but the end notes don't have all verses present in first document. Some verse (paragraph) of the first document have not related verse in end_notes document.
Sample of First document:
Gen 1:1
Gen 1:2
Gen 1:3
Gen 1:4
Gen 1:5
and so on
Sample of second (end_notes);
Gen 1:2
Gen 1:3
Gen 1:5
and so on
pasquale
ecc ecc
MOS MASTER
07-28-2005, 09:24 AM
Hi Pasquale,
You can move your curly brace using Find and Replace ..
Check Use Wildcards
Find Text: \{(*)\}(*)^13
Replace Text: {\1\2}^13
Just hit Replace All
(and record it if you want code)
Hi Tony, :yes
Excellent! :clap:
TonyJollans
07-28-2005, 12:06 PM
Sorry, I didn't get round to this until now. I have just knocked up something real quick and it is very messy and I have no more time at the moment. I can post it if you like but would prefer to tidy it up.
It does work .. until it hits a note like ...
[Eb 7,11-14] L`argomentazione .....
What should I do with this - add it to verse 11?
Another example from looking very quickly is ..
[Eb 9,15-28] Questo ...
[Eb 9,22] tutte ...
...
[Eb 9,28] ...
This makes me wonder if I'll ever find something like this ..
[Eb 9,15-28] Questo ...
[Eb 9,15] ...
......
In other words, two notes for the same verse. Can this happen and if it does what should I do?
Pasquale
07-28-2005, 12:24 PM
Hallo, There is problem with notes, some notes concern miscellaneous verses.
The rule to observe is this: [ Eb 7 (chapter) :11 (verse) - 14 (don't consider)
Two notes on the same verse must be append at the end of the same verse.
Therefore it is possible che one bible verse sample:
Heb 9:15 may have two or three end-notes appended
Sample:
Heb 9:15 Per questo egli ? mediatore di una nuova alleanza, perch?, essendo ormai intervenuta la sua morte per la rendenzione delle colpe commesse sotto la prima alleanza, coloro che sono stati chiamati ricevano l' eredit? eterna che ? stata promessa.{Heb 9:15 stati chiamati riceva}{Heb 9:15-28 ecc ecc}
Heb 9:16 Dove infatti c' ? un testamento, ? necessario che sia accertata la morte del testatore,
Thanks
pasquale
TonyJollans
07-28-2005, 04:48 PM
Hi Pasquale,
A bit rough and ready but I think this will work.
It uses two open Documents:
a single (bible) book, and
the notes for that book
You need to hard code the document names where shown.
It creates a new document with the merged text.
I have tested with the Book of Hebrews from your posted file.
The abbreviation from the Book is used for both the verses and the notes - no check is made of the abbreviation in the Notes.
It assumes that the verses in the Book are in the format ...
Book Chapter:Verse Text
And that the notes are in the format ...
[Book Chapter, Verse-Verse] Note_Text
The (square) brackets round the chapter and verse are replaced with (curly) braces round the entire note.
That's about it - here's the code. Just drop it into a new module:
Dim docNotes As Document
Dim rngNote As Range
Dim numNotesPara As Long
Dim numNoteChapter As Long
Dim numNoteVerse As Long
Sub MergeNotes()
Dim docBook As Document
Dim docMerge As Document
Dim paraVerse As Paragraph
Dim rngVerse As Range
Dim BookVerseAndChapter
Dim VerseAndChapter
Dim abbrBook As String
Dim numBookChapter As Long
Dim numBookVerse As Long
Set docBook = Documents("Book.doc") ' Name of the Book Document
Set docNotes = Documents("Notes.doc") ' Name of the Notes Document
Set docMerge = Documents.Add
numNotesPara = 0
GetNextNote
For Each paraVerse In docBook.Paragraphs
Set rngVerse = paraVerse.Range
rngVerse.MoveEndWhile vbCr & Space(1), wdBackward
BookVerseAndChapter = Split(rngVerse, , 3)
abbrBook = BookVerseAndChapter(0)
VerseAndChapter = Split(BookVerseAndChapter(1), ":")
numBookChapter = Val(VerseAndChapter(0))
numBookVerse = Val(VerseAndChapter(1))
With docMerge
.Range(.Content.End - 1, .Content.End - 1) = rngVerse.Text
If Not rngNote Is Nothing Then
Do While numBookChapter = numNoteChapter And numBookVerse = numNoteVerse
.Range(.Content.End - 1, .Content.End - 1) _
= " {" & abbrBook & " " & numNoteChapter & "," & _
numNoteVerse & " " & rngNote.Text & "}"
GetNextNote
If rngNote Is Nothing Then Exit Do
Loop
End If
.Range(.Content.End - 1, .Content.End - 1) = vbNewLine
End With
Next
Set rngNote = Nothing
Set rngVerse = Nothing
Set docMerge = Nothing
Set docNotes = Nothing
Set docBook = Nothing
End Sub
Sub GetNextNote()
Dim ChapterAndVerse
Do
numNotesPara = numNotesPara + 1
If numNotesPara > docNotes.Paragraphs.Count Then
Set rngNote = Nothing
Exit Do
Else
Set rngNote = docNotes.Paragraphs(numNotesPara).Range
If Trim(rngNote.Text) <> vbCr Then Exit Do
End If
Loop
If Not rngNote Is Nothing Then
ChapterAndVerse = Split(Split(Split(Split(rngNote.Text, "]")(0), "[")(1))(1), ",")
numNoteChapter = Val(ChapterAndVerse(0))
numNoteVerse = Val(Split(ChapterAndVerse(1), "-")(0))
rngNote.MoveStartUntil "]", wdForward
rngNote.MoveStartWhile "]" & Space(1), wdForward
rngNote.MoveEndWhile vbCr & Space(1), wdBackward
End If
End Sub
Pasquale
07-28-2005, 09:56 PM
Hallo Tony,
today I shall test the macro.
Thanks
pasquale
Pasquale
07-29-2005, 06:18 AM
Wonderful, works very well.
Ony a little problem when the end notes is so [Gen 16] without a comma , and other number, macro stops and open debug.
Therfore I first to launch macro manually find in the Notes.doc the number without comma and another number and replace so - sample find [Gen 16] and replace with [Gen 16,1]. And so for all Notes.doc.
It is possible automate so when there isn't the comma and a number after comma to put the number 1 (for convention)? Sample [Heb 6] replace with [Heb 6,1] ecc.
Thanks very very much
pasquale
TonyJollans
07-29-2005, 06:39 AM
Hi Pasquale,
Try changing this line (about 8 lines from the end):
From:
ChapterAndVerse = Split(Split(Split(Split(rngNote.Text, "]")(0), "[")(1))(1), ",")
To
ChapterAndVerse = Split(Split(Split(Split(rngNote.Text, "]")(0), "[")(1))(1) & ",1", ",")
Pasquale
07-29-2005, 10:09 AM
Test,
work work work very well
wonderful, wonderful
many many thanks Tony
pasquale
TonyJollans
07-29-2005, 10:30 AM
My pleasure :thumb
MOS MASTER
07-29-2005, 02:47 PM
Hi pasquale, :yes
Don't forget to mark your thread solved?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.