rlaumen
12-16-2007, 05:47 AM
Hi,
(This is my first post, so please bear with me and take into account that I am not a VBA guru - otherwise I could have come up with something myself ;) )
I would like to create a macro that inserts a space between a number and a unit of measure (e.g. 64MB should become 64 MB, etc.).
I've got:
=============================
Sub InsertSpaceBetweenNumberAndUnit()
'
' InsertSpaceBetweenNumberAndUnit Macro
'
' This one is for MB
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9])(MB)"
.Replacement.Text = "\1 \2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
' This one is for GB
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9])(GB)"
.Replacement.Text = "\1 \2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End sub
=============================
But if I need to add more units in addition to MB and GB, the code will become very long. I will probably need a short code containing an array or something.
Please note that I do not need something that simple puts a space between any number and any letter if there is none, as that would change product numbers etc. as well, and I don't want that.
Any ideas?
TIA,
Rob
(This is my first post, so please bear with me and take into account that I am not a VBA guru - otherwise I could have come up with something myself ;) )
I would like to create a macro that inserts a space between a number and a unit of measure (e.g. 64MB should become 64 MB, etc.).
I've got:
=============================
Sub InsertSpaceBetweenNumberAndUnit()
'
' InsertSpaceBetweenNumberAndUnit Macro
'
' This one is for MB
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9])(MB)"
.Replacement.Text = "\1 \2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
' This one is for GB
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9])(GB)"
.Replacement.Text = "\1 \2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End sub
=============================
But if I need to add more units in addition to MB and GB, the code will become very long. I will probably need a short code containing an array or something.
Please note that I do not need something that simple puts a space between any number and any letter if there is none, as that would change product numbers etc. as well, and I don't want that.
Any ideas?
TIA,
Rob