View Single Post
 
Old 05-29-2019, 03:38 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by skeezix View Post
  1. What do I do with the code that was posted?
  2. About the line "Sub Demo () - is that a generic line, or can I change the "demo" to something else?
  3. And if I want to use the macro for "( )" marks instead of quotes, do I need to make another macro or can I use the above and somehow add to it??
Since you asked for a macro, one would have assumed you'd know what to do with one.
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html

The macro name 'Demo' can be changed to any valid name you care to use.


As for parens, brackets, etc., you might re-code the sub as:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrEnc As String, ChrA As String, ChrB As String
StrEnc = InputBox("What are the enclosing charaters?" & vbCr & "(e.g. <>, (), [], {}, «», '', """")")
Select Case StrEnc
  Case "<>": ChrA = "<": ChrB = ">"
  Case "()": ChrA = "(": ChrB = ")"
  Case "[]": ChrA = "[": ChrB = "]"
  Case "{}": ChrA = "{": ChrB = "}"
  Case "«»": ChrA = "«": ChrB = "»"
  Case "''": ChrA = Chr(145): ChrB = Chr(146)
  Case Chr(34) & Chr(34): ChrA = Chr(147): ChrB = Chr(148)
  Case Else: Exit Sub
End Select
With Selection
  .InsertBefore ChrA
  .InsertAfter ChrB
End With
Application.ScreenUpdating = True
End Sub
Note that if you run the macro repeatedly on the same selection, you'll get a nesting of the chosen characters.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote