Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 37 of 37

Thread: Solved: MergeText

  1. #21
    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

    [vba]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[/vba]

  2. #22
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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 .. [VBA]

    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[/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #23
    Hallo Tony

    it is a better better macro

    It is OK

    for my work

    thanks pasquale

  4. #24
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #25
    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

  6. #26
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  7. #27
    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

  8. #28
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by TonyJollans
    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,

    Excellent!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  9. #29
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  10. #30
    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

  11. #31
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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:
    [VBA]
    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
    [/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  12. #32
    Hallo Tony,
    today I shall test the macro.

    Thanks
    pasquale

  13. #33
    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

  14. #34
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Pasquale,

    Try changing this line (about 8 lines from the end):

    From:

    [VBA]ChapterAndVerse = Split(Split(Split(Split(rngNote.Text, "]")(0), "[")(1))(1), ",")[/VBA]

    To

    [VBA]ChapterAndVerse = Split(Split(Split(Split(rngNote.Text, "]")(0), "[")(1))(1) & ",1", ",")[/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  15. #35
    Test,

    work work work very well

    wonderful, wonderful

    many many thanks Tony

    pasquale

  16. #36
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    My pleasure
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  17. #37
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi pasquale,

    Don't forget to mark your thread solved?
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •