Results 1 to 14 of 14
  1. #1
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Help integrating pargph. mark and tabs in wildcard (MS Office 2003)

    Can you edit your post to avoid the horizontal scrolling (e.g., break your long string into two parts, separated by & ).

    <hr>The trouble I am having is that the two tab characters in the .text line below are not being recognized when the code runs.<hr>
    You have sequences of two tabs and the code is not finding them? Can you find them in an interactive search using the Find dialog?

    <hr>However, a paragraph mark is not compatible with a wildcard search.<hr>
    In a wildcard search, use ^13 in place of ^p.

  2. #2
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help integrating pargph. mark and tabs in wild

    Thank you for the response. How do I edit a post after the post has been established?

  3. #3
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help integrating pargph. mark and tabs in wildcard (MS Office 2003)

    Edited by HansV to break excessively long line that caused horizontal scrolling and to correct link to post

    This post is about an MSWord macro.

    I am trying to adapt Macropod's excellent code work found in the thread below. The trouble I am having is that the two tab characters in the .text line below are not being recognized when the code runs. Ideally, I would like the following line to be as follows:

    <code> .Text = "^p" & "^t^t" & Bookname & "*" </code>

    However, a paragraph mark is not compatible with a wildcard search.

    The link to the code originally posted by Macropod is... <post#=721429>post 721429</post#>

    <code>
    '
    ' RedoMacroZeroAdder Macro
    '
    '
    Dim Books As String
    Dim Bookname As String
    Dim i As Integer
    Books = "Gen,Exo,Lev,Num,Deu,Jos,Jdg,Rth,1Sa,2Sa,1Ki,2Ki,1 Ch,2Ch,Ezr,Neh,Est,Job," & _
    "Psa,Pro,Ecc,Son,Isa,Jer,Lam,Eze,Dan,Hos,Joe,Amo,O ba,Jon,Mic,Nah,Zep,Hag,Zec,Mal," & _
    "Mat,Mar,Luk,Joh,Act,Rom,1Co,2Co,Gal,Eph,Php,Col,1 Th,2Th,1Ti,2Ti,Tit,Phm,Heb,Jas," & _
    "1Pe,2Pe,1Jn,2Jn,3Jn,Jud,Rev,End"
    For i = 0 To UBound(Split(Books, ","))
    Bookname = Split(Books, ",")(i)
    With ActiveDocument.Content.Find
    .ClearFormatting
    .Text = "^t^t" & Bookname & "*"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute

    Selection.Find.ClearFormatting
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = " - ^p"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=":0"
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Next
    End Sub
    </code>
    I am still trying to work out the details of the code operation.

    Thank you in advance for any replies.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Help integrating pargph. mark and tabs in wildcard (MS Office 2003)

    When searching with wildcards, you can use ^13 to denote a paragraph mark.

    See Phil Rabichow's star post Re: Find/Replace Special Characters (Word) for other special codes you can use.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Help integrating pargph. mark and tabs in wild

    I have already edited your post for you. You can do it yourself by clickcing the <IMG SRC=http://www.wopr.com/w3timages/edit.gif> button in the post header.

  6. #6
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help integrating pargph. mark and tabs in wild

    Thank you for the helpful suggestions. I will work on these and report back my results. Thank you again for your time and help.

  7. #7
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help integrating pargph. mark and tabs in wild

    Thank you again for your time and responses.

    I have implemented the suggestions but am now finding i have other issues.

    The purpose of the macro is to place a colon and a zero after any occurrence of any book name found in the text. The bookname must be in a line of text bounded by paragraph marks on both ends of the text line and the text line must have with two tabs after the left most paragraph mark.

    So, I changed the .Text line to this... .Text = "^13^9^9" & Bookname & "*" & "^13"
    which should make the macro find lines only bounded by paragraph marks on both ends of the text line and with two tabs after the left most paragraph mark.

    However, the macro is not working like I need it to work. What is happening now is that no matter whether the text line contains a leading paragraph mark and two tabs or not, the colon and zero are appended to any book name irregardless of the content of the text line. I think I need an if statement in the macro so the lower block of text starting at the line...

    Selection.MoveLeft Unit:=wdCharacter, Count:=1

    does not execute unless the .text line is actually found.

    Can someone give me a suggestion on how to implement a condition statement so only the lower block of text executes if conditions in .text are met?

    Sub TryOne
    Dim Books As String
    Dim Bookname As String
    Dim i As Integer
    Books = "Gen,Exo,Lev,Num,Deu,Jos,Jdg,Rth,1Sa,2Sa,1Ki,2Ki,1 Ch,2Ch,Ezr,Neh,Est,Job,Psa,Pro,Ecc,&_
    Son,Isa,Jer,Lam,Eze,Dan,Hos,Joe,Amo,Oba,Jon,Mic,Na h,Zep,Hag,Zec,Mal,Mat,Mar,Luk,Joh,Act,Rom,&_
    1Co,2Co,Gal,Eph,Php,Col,1Th,2Th,1Ti,2Ti,Tit,Phm,He b,Jas,1Pe,2Pe,1Jn,2Jn,3Jn,Jud,Rev,End"
    For i = 0 To UBound(Split(Books, ","))
    Bookname = Split(Books, ",")(i)
    With ActiveDocument.Content.Find
    .ClearFormatting
    .Text = "^13^9^9" & Bookname & "*" & "^13"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute

    'THE FOLLOWING LINES WERE COMMENTED OUT

    'Selection.Find.ClearFormatting
    'Selection.MoveRight Unit:=wdCharacter, Count:=1
    'Selection.Find.ClearFormatting
    'With Selection.Find
    ' .Text = " - ^p"
    ' .Replacement.Text = ""
    ' .Forward = True
    ' .Wrap = wdFindContinue
    ' .Format = False
    ' .MatchCase = False
    ' .MatchWholeWord = False
    ' .MatchWildcards = False
    ' .MatchSoundsLike = False
    ' .MatchAllWordForms = False
    ' End With
    ' Selection.Find.Execute

    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=":0"
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveRight Unit:=wdCharacter, Count:=1

    Next

    End Sub

    Thank you in advance for you time and replies.

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Help integrating pargph. mark and tabs in wild

    You can probably do this using suitable replacement text with a wildcard search.
    It would be a bit easier to help you if you could post an example of the text you want to replace, the text you want to replace it with, and some similar text that you want to leave alone.

    To answer your direct question. If you only want something to execute if the search is successful then you can replace
    <code>Selection.Find.Execute</code>
    with
    <code>If Selection.Find.Execute
    <font color=448800> ' code to execute on a successful search goes here</font color=448800>
    End If</code>

    StuartR

  9. #9
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Help integrating pargph. mark and tabs in wild

    Hi HowdeeDoodee,

    I think the code you're after is something like:
    Sub ZeroAdder()
    Dim Books As String
    Dim Bookname As String
    Dim i As Integer
    Books = "Gen,Exo,Lev,Num,Deu,Jos,Jdg,Rth,[1-2]Sa,[1-2]Ki,[1-2]Ch,Ezr,Neh,Est,Job,Psa,Pro,Ecc," & _
    "Son,Isa,Jer,Lam,Eze,Dan,Hos,Joe,Amo,Oba,Jon,Mic,N ah,Zep,Hag,Zec,Mal,Mat,Mar,Luk,Joh,Act," & _
    "Rom,[1-2]Co,Gal,Eph,Php,Col,[1-2]Th,[1-2]Ti,Tit,Phm,Heb,Jas,[1-2]Pe,[1-3]Jn,Jud,Rev,End"
    For i = 0 To UBound(Split(Books, ","))
    Bookname = Split(Books, ",")(i)
    With ActiveDocument.Content.Find
    .ClearFormatting
    .Text = "(^13^t^t" & Bookname & ")([0-9a-zA-Z&]{1,}^13)"
    .Replacement.Text = "1:02"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
    End With
    Next
    End Sub

    Note that I've also reduced the array size by replacing the numbered books (eg 1Ki, 2Ki becomes [1-2]Ki). This should speed up the execution by reducing the number of iterations and, more importantly, prevents the ^9 code (which I've replaced with ^t anyway) combining with a following number - and erroring out on 3Jn. One could use '?' instead of the '[1-2]' and '[1-3]' strings in the array for an even greater increase in speed, but I was concerned that might lead to false matches with other strings in your text. You can check for yourself & modify if you wish. You might want to change the array for <post#=721429>post 721429</post#> the same way - indeed you could use the same array for both subs.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  10. #10
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help integrating pargph. mark and tabs in wild

    Thank you MacroPod. I copied and pasted your suggestions into a macro and I did not get anything to change on a sample page during the macro run. The whole sample page was selected during the macro run but no colons or zeros were added to any of the book abbreviations. Here is a sample of the kind of text on the page to be changed. The paragraph marks do not show on this forum page nor do the tab marks. Here is a sample of Before processing and After processing. Here are partial contents of the sample page.

    Before Processing With The Macro

    Gen 44 -

    Content line goes here.
    Content line goes here

    Exo 44 -

    Content line goes here.
    Content line goes here

    Lev 44 -

    Content line goes here.
    Content line goes here

    Num 44 -

    Content line goes here.
    Content line goes here

    1Ch 44 -

    Content line goes here.
    Content line goes here

    2Ch 44 -

    After Processing With The Macro

    Gen 44:0 -

    Content line goes here.
    Content line goes here

    Exo 44:0 -

    Content line goes here.
    Content line goes here

    Lev 44:0 -

    Content line goes here.
    Content line goes here

    Num 44:0 -

    Content line goes here.
    Content line goes here

    1Ch 44:0 -

    Content line goes here.
    Content line goes here

    2Ch 44:0 -

    After the macro is working, I will need to change the macro to recognize the book names to their full non-abbreviated counter parts. I left out the full non-abbreviated book names in my original post for simplicity .

    Thank you again for your reponses.

  11. #11
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Help integrating pargph. mark and tabs in wild

    Try changing the .Text line to
    <code> .Text = "(^13^t^t" & Bookname & " [0-9a-zA-Z&]{1,})( - ^13)"</code>

    The original code did not match because you have a space after the bookname, and the text " - " after the number.
    Also make sure that you have paragraph marks before each book reference, when I pasted this text into word it appeared as new line characters rather than paragraphs.

    StuartR

  12. #12
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Help integrating pargph. mark and tabs in wild

    <P ID="edit" class=small>(Edited by macropod on 04-Aug-08 08:31. Correction: The code I posted looks for paragraphs starting with two tabs followed by the bookname and then any alpha-numeric string and adds the ':0' after the bookname. )</P>Hi HowdeeDoodee,

    In <post#=724946>post 724946</post#> you said
    <hr>The purpose of the macro is to place a colon and a zero after any occurrence of any book name found in the text. The bookname must be in a line of text bounded by paragraph marks on both ends of the text line and the text line must have with two tabs after the left most paragraph mark.<hr>
    The code I posted looks for just such paragraphs and adds the ':0' after the bookname. Hence:

    ^t^tGen 44 -
    becomes

    ^t^tGen:0 44 -
    That is what you asked for.

    I get the impression, though, that what you wanted to end up with was:

    ^t^tGen 44:0 -
    Is that correct?

    As for the full names of the books, incorporating them into the process is simply a matter of adding them to the array. '1 Kings' and '2 Kings', for example, would be coded as '[1-2] Kings'.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  13. #13
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Help integrating pargph. mark and tabs in wild

    Hi Stuart,

    If HowdeeDoodee wants to change

    Gen 44 -
    to

    Gen 44:0 -
    and if all that is on the line after the number (which I already know to be no more than 3 digits long) is ' - ', then he could use:
    .Text = "(^13^t^t" & Bookname & " [0-9]{1,3})( - ^13)"
    Otherwise, it might be better to use:
    .Text = "(^13^t^t" & Bookname & " [0-9]{1,3}" & ")([^32-^255]{1,})"
    to capture any possible following text string, including tabs, hard spaces, newlines etc.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  14. #14
    Star Lounger
    Join Date
    Jul 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help integrating pargph. mark and tabs in wild

    Thank you, MacroPod. I decided to use the code line...

    .Text = "(^13^t^t" & Bookname & " [0-9]{1,3}" & ")([^32-^255]{1,})"

    Thank you to all the posters for your contributions.

Posting Permissions

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