Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Changing Roman Numerals to Arabic.
Written by Allen Wyatt (last updated July 22, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365
Bradley has a document that has, within text, many Roman numerals. He needs an easy way to change these thousands of Roman numerals to Arabic. These are not fields of any nature; they are simply typed in text as Roman numerals. He wonders if there is a way to easily change them to their Arabic equivalents.
Unfortunately, there is no function in Word that will convert Roman numerals to Arabic. You could, if you want, simply use Find and Replace to search for Roman numerals, but you would have to do an individual search for each one. You could use a wild card search to search for a word that consists entirely of uppercase Roman numerals, which would make searching quite a bit easier. All you need to do is search for "<[CDILMVX]{1,}>" (without the quote marks) and make sure you have the Use Wild Cards check box selected. When you click Find Next, the next Roman numeral is located, and you can then manually change it to its Arabic equivalent.
Another way to try to do the conversion is with a macro. You could create a macro that looks at each word in your document and tries to determine if it is a candidate for consisting of Roman numerals. You may get some false positives, though, particularly if your document contains acronyms that could be confused as Roman numerals. (For example, if you use the acronym CC for credit card, that could be considered the Roman numeral for 200.)
The following set of macros will step through each of the words in a document and if the word contains only Roman numerals (I, V, X, L, C, D, and M) then the user is asked if the macro should convert the numerals.
Sub ConvertRoman() Dim wrdX Dim wrd As String Dim tstSW As Boolean Dim J As Long For Each wrdX In ActiveDocument.Words wrd = UCase(Trim(wrdX)) If wrd = "" Or wrd = "I" Or wrd = vbCr Then tstSW = False Else tstSW = True End If For J = 1 To Len(wrd) If InStr("MDCLXVI",Mid(wrd, J, 1)) = 0 Then tstSW = False Exit For End If Next J If tstSW Then wrdX.Select Selection.MoveLeft unit:=wdCharacter, _ Count:=Len(wrdX) - Len(wrd), _ Extend:=wdExtend J = MsgBox("Convert " & wrd & " to Arabic", vbYesNoCancel) If J = vbCancel Then Exit Sub If J = vbYes Then Selection.TypeText Text:=RomanToArabic(wrd) End If Next wrdX End Sub
Function RomanToArabic(Rm As String) As String Dim J As Long Dim ab As Long Dim cc As Long Dim dd As Long ab = 0 Rm = Trim(Rm) J = 1 Do cc = GetValue(Mid(Rm, J, 1)) dd = GetValue(Mid(Rm, J + 1, 1)) If cc < dd Then ab = ab + dd - cc J = J + 1 Else ab = ab + cc End If J = J + 1 Loop Until J >= Len(Rm) If J = Len(Rm) Then ab = ab + GetValue(Mid(Rm, J, 1)) End If RomanToArabic = Trim(Str(ab)) End Function
Function GetValue(ss As String) As Long Dim Cde() Dim Cvalue() Dim J As Long Cde = Array("M", "D", "C", "L", "X", "V", "I") Cvalue = Array(1000, 500, 100, 50, 10, 5, 1) For J = 0 To 6 If ss = Cde(J) Then GetValue = Cvalue(J) Exit Function End If Next J GetValue = 999999 End Function
Since an uppercase I is a very common word in text, the macros won't stop on each of them to determine if a conversion should be done. However, if the capital I is part of a longer word that consists of only Roman numerals (such as XLVII), then it is considered a candidate for conversion. The macros also assume that all your Roman numerals are uppercase.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (5943) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Changing Roman Numerals to Arabic.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Macros are often used to process documents, resulting in changes of one manner or another. If you need your macro to add ...
Discover MoreNeed to format your document using a macro? You can easily set the right margin for an individual paragraph by using the ...
Discover MoreWhen you distribute documents to other people, you may want those documents to have associated macros that the reader can ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments