FindNextUnit:
unitRng.Select
For i = LBound(findUnit) To UBound(findUnit)
If Trim(unitRng.Text) = findUnit(i) Then
MsgBox (findUnit(i) & " will be replaced by " & repUnit(i))
unitRng.Select
Set nUnitRng = unitRng
nUnitRng.Next(unit:=wdWord, Count:=1).Select
Set nUnitRng = Selection.Range
nUnitRng.Select
MsgBox ("Next Unit Preselected")
unitRng.Select
Selection.TypeText (repUnit(i))
Set unitRng = nUnitRng
unitRng.Select
MsgBox ("Next Unit")
GoTo FindNextUnit
End If
Next i
ASKER
ASKER
Sub MultipleReplace(rngArea As Range, findUnit() As String, repUnit() As String)
Dim i As Integer
For i = LBound(findUnit) To UBound(findUnit)
With rngArea.Find
.Text = "(<[0-9]{1,})" & findUnit(i) 'word must be numeric, followed by required text
.MatchWildcards = True
.Replacement.Text = "\1" & repUnit(i) 'replace with text "\1" in first pair of () brackets & new text
.Execute Replace:=wdReplaceAll
End With
Next i
End Sub
ASKER
ASKER
ASKER
ASKER
Sub FixUnits()
Dim findUnit As Variant
Dim repUnit As Variant
Dim unitRng As Range
findUnit = Array("second", "per", "meters", "amp", "hertz", "hz", "litres", "minute", "mpa", "kpa", "gpl", "minutes", "hours")
repUnit = Array("s ", "/ ", "m ", "A ", "Hz ", "Hz ", "L ", "min ", "MPa ", "kPa ", "g/L ", "min ", "hr ")
MultipleReplace Selection.Range, findUnit(), repUnit()
End Sub
Sub MultipleReplace(rngArea As Range, findUnit() As String, repUnit() As String)
Dim i As Integer
For i = LBound(findUnit) To UBound(findUnit)
With rngArea.Find
.Text = "(<[0-9]{1,})" & findUnit(i) 'word must be numeric, followed by required text
.MatchWildcards = True
.Replacement.Text = "\1" & repUnit(i) 'replace with text "\1" in first pair of () brackets & new text
.Execute Replace:=wdReplaceAll
End With
Next i
End Sub
ASKER
ASKER
ASKER
ASKER
ASKER
NextUnit:
For i = LBound(findUnit) To UBound(findUnit)
unitRng.End = unitRng.Start + Len(findUnit(i))
unitRng.Select
' MsgBox (unitRng)
If Trim(unitRng.Text) = Trim(findUnit(i)) Then
unitRng.Select
ync = MsgBox(findUnit(i) & " will be replaced by " & repUnit(i), vbYesNoCancel)
If ync = vbYes Then
unitRng.Text = repUnit(i)
Selection.Expand unit:=wdWord
Selection.Collapse direction:=wdCollapseEnd
Set unitRng = Selection.Range
GoTo NextUnit 'Exit For
Else
If ync = vbCancel Then GoTo myEnd
End If
End If
Next i
ASKER
Microsoft Word is a commercial document editing program that is part of the Microsoft Office suite. It features numerous text-editing tools for creating richly formatted documents, along with tools for the use of macros in Word documents. Word's native file formats are denoted either by a .doc or .docx file extension. Plugins permitting the Windows versions of Word to read and write formats it does not natively support, such as the OpenDocument format (ODF) are available. Word can import and display images in common bitmap formats such as JPG and GIF. It can also be used to create and display simple line-art.
TRUSTED BY
Open in new window