Consulting

Results 1 to 4 of 4

Thread: Add Hebrew calendar dates to Gregorian calendar dates in Word text

  1. #1
    VBAX Newbie
    Joined
    Dec 2013
    Posts
    2
    Location

    Smile Add Hebrew calendar dates to Gregorian calendar dates in Word text

    Hi All,I'm a newbie so please bear with me. I have a text in MS Word that has dates in Gregorian calendar, I'd like to add the Hebrew calendar dates as well. One example: ORIGINAL TEXT:Rav Iom Tov Lipmann Heller (Tosafot Iom Tov)..............................................................1580-1655 NEEDED TEXT:Rav Iom Tov Lipmann Heller (Tosafot Iom Tov)..............................................................5340-5415 (1580-1655) Hebrew calendar = Gregorian calendar + 3760 My list has around 300 entries so I can't do this by hand. I've managed to find the string containing the original dates like this: With Selection .Find.Text = "" .Forward = True .Wrap = wdFindContinue .MatchWildcards = True End With I'm using this to set the replacement string: Selection.Find.Replacement.Text = [whatever goes here] But I get stuck when I want to add 3760 to \1 and to \2 (\1 and \2 being the first and second [0-9]{4}, respectively). VBA won't let my assign \1 or \2 to variables so I can't add 3760 and to put together the replacement string. Thanks for all your help! Martín

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Try:
    Sub Demo()
    Application.ScreenUpdating = False
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "<[0-9]{4}>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchWildcards = True
        .Execute
      End With
      Do While .Find.Found
        .Text = CLng(.Text) + 3670
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
    End With
    Application.ScreenUpdating = True
    End Sub
    PS: Your code is difficult to make sense of. When posting code, please use the code tags. They're on the 'Go Advanced'
    tab.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Dec 2013
    Posts
    2
    Location
    Thank you so much! Below's an alternative that someone suggested that will do the double dates. It works perfectly:

    With Selection.Find
    .Text = "<([0-9]{4})-([0-9]{4})>"
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Execute
    End With
    dte = Selection.Range.Text
    hdte = Split(dte, "-")
    ndte = hdte(0) + 3760 & "-" & hdte(1) + 3760 & " (" & dte & ")"
    
    With Selection.Find
    .Text = dte
    .Replacement.Text = ndte
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Execute , , , , , , , , , , True
    End With



    Quote Originally Posted by macropod View Post
    Try:
    Sub Demo()
    Application.ScreenUpdating = False
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "<[0-9]{4}>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchWildcards = True
        .Execute
      End With
      Do While .Find.Found
        .Text = CLng(.Text) + 3670
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
    End With
    Application.ScreenUpdating = True
    End Sub
    PS: Your code is difficult to make sense of. When posting code, please use the code tags. They're on the 'Go Advanced'
    tab.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    The fundamental difference is that my code works with dates that don't have a hyphen separator as well as those that do. Still, if you only want to work with 'double dates' with a hyphen separator, my code can do that by changing:
    .Text = "<[0-9]{4}>"
    to:
    .Text = "<[0-9]{4}>-<[0-9]{4}>"
    and changing:
    .Text = CLng(.Text) + 3670
    to:
    .Text = CLng(split(.Text,"-")(0)) + 3670 & "-" & CLng(split(.Text,"-")(1))
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

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