menteith
09-25-2016, 05:23 AM
Hi all,
I'd like to create a macro in Word (I use 2016) which replaces hyphenes with en-dashes ("a longer hyphen"). I think when I paste a hyphen in this forum I automatically becomes an dash. Wikipedia has a nice article on hyphens (https://en.wikipedia.org/wiki/Hyphen) and dashes (https://en.wikipedia.org/wiki/Dash).
Here's my code (recorded and edited my me):
Sub plusminus()
With Selection.Find
.Text = " - " ' it should be hyphen here but VBA editor and this forum changes it to a dash
.Replacement.Text = " – " ' en dash is here
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
When I try to copy and paste a hyphen to VBA editor I always get en dash. If I try to press a hyphen key on my keyboard I always get en dash. In consequence, the macro won't work. How do I replace hyphens en dashes using VBA?
Thanks!
I'd like to create a macro in Word (I use 2016) which replaces hyphenes with en-dashes ("a longer hyphen"). I think when I paste a hyphen in this forum I automatically becomes an dash. Wikipedia has a nice article on hyphens (https://en.wikipedia.org/wiki/Hyphen) and dashes (https://en.wikipedia.org/wiki/Dash).
Here's my code (recorded and edited my me):
Sub plusminus()
With Selection.Find
.Text = " - " ' it should be hyphen here but VBA editor and this forum changes it to a dash
.Replacement.Text = " – " ' en dash is here
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
When I try to copy and paste a hyphen to VBA editor I always get en dash. If I try to press a hyphen key on my keyboard I always get en dash. In consequence, the macro won't work. How do I replace hyphens en dashes using VBA?
Thanks!