View Single Post
 
Old 06-03-2014, 09:39 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Something like this should get you started:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range, oRngNums As Range
Dim strNums As String
Dim arrEng() As String, arrMet() As String, arrFactors() As String
Dim lngIndex As Long
  arrEng = Split("gpm,mph,yds", ",")
  arrMet = Split("lpm,kph,m", ",")
  arrFactors = Split("3.785,1.60934,.9144", ",")
  For lngIndex = 0 To UBound(arrEng)
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = arrEng(lngIndex)
    While .Execute
      oRng.Select
      If MsgBox("Do you want to show dual values?", vbYesNo, "CREATE DUAL VALUE") = vbYes Then
        Set oRngNums = oRng.Duplicate
        oRngNums.Collapse wdCollapseStart
        oRngNums.MoveStartWhile Cset:="1234567890 ", Count:=wdBackward
        strNums = Trim(oRngNums.Text)
        oRng.Text = arrEng(lngIndex) & " (" & CDbl(arrFactors(lngIndex)) * CDbl(strNums) & " " & arrMet(lngIndex) & ")"
        oRng.Collapse wdCollapseEnd
      Else
        oRng.Collapse wdCollapseEnd
      End If
    Wend
  End With
  Next lngIndex
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote