PDA

View Full Version : [SOLVED:] Add Hebrew calendar dates to Gregorian calendar dates in Word text



tinchox
12-12-2013, 07:27 PM
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

macropod
12-12-2013, 09:49 PM
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.

tinchox
12-13-2013, 06:27 AM
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






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.

macropod
12-13-2013, 02:21 PM
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))