Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-31-2016, 09:42 AM
c1905 c1905 is offline Editing styles with macros/VBA: a simple question Windows 7 64bit Editing styles with macros/VBA: a simple question Office 2010 32bit
Novice
Editing styles with macros/VBA: a simple question
 
Join Date: Aug 2016
Posts: 3
c1905 is on a distinguished road
Default Editing styles with macros/VBA: a simple question

Greetings,

I'm using Office Professional Plus 2010 on Win 7 64 bit. I'm trying to create a style that (among other things) automatically wraps parentheses around text once the style is applied. I found no simple way to do it, but someone somewhere suggested using the following code:

Code:
Sub AddParens()
    Selection.InsertBefore "("
    Selection.InsertAfter ")"
End Sub
I understand that this is some sort of macro or VBA, but I cannot figure out how to modify my style (let's call it "paren") using that code. I've made many searches and all I could found was many examples of codes without any explanation of where exactly they are to be added. I have the developer ribbon visible and I played around with the "macros" and "visual basic" tabs, but could find nothing there to help me.

Your help is appreciated.
Reply With Quote
  #2  
Old 09-01-2016, 03:21 AM
macropod's Avatar
macropod macropod is offline Editing styles with macros/VBA: a simple question Windows 7 64bit Editing styles with macros/VBA: a simple question Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

You cannot modify a Style in the way you propose. Styles only affect the formatting of the content in the range to which it is applied; they cannot change the content.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-01-2016, 04:17 AM
c1905 c1905 is offline Editing styles with macros/VBA: a simple question Windows 7 64bit Editing styles with macros/VBA: a simple question Office 2010 32bit
Novice
Editing styles with macros/VBA: a simple question
 
Join Date: Aug 2016
Posts: 3
c1905 is on a distinguished road
Default

Thank you for the response. So, is there a way to force parentheses around a piece of selected text? I assume the code quoted above does work, somehow.
Reply With Quote
  #4  
Old 09-01-2016, 04:42 AM
gmayor's Avatar
gmayor gmayor is offline Editing styles with macros/VBA: a simple question Windows 10 Editing styles with macros/VBA: a simple question Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

See http://www.gmayor.com/installing_macro.htm. It will help to associate the macro with a keyboard shortcut or add a button to the QAT (Quick Access Toolbar) or Ribbon. Both are covered in the linked page.

Select the text and run the macro.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 09-01-2016, 04:45 AM
c1905 c1905 is offline Editing styles with macros/VBA: a simple question Windows 7 64bit Editing styles with macros/VBA: a simple question Office 2010 32bit
Novice
Editing styles with macros/VBA: a simple question
 
Join Date: Aug 2016
Posts: 3
c1905 is on a distinguished road
Default

Thank you. I'll do that.
Reply With Quote
  #6  
Old 09-01-2016, 06:23 AM
macropod's Avatar
macropod macropod is offline Editing styles with macros/VBA: a simple question Windows 7 64bit Editing styles with macros/VBA: a simple question Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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 c1905 View Post
So, is there a way to force parentheses around a piece of selected text? I assume the code quoted above does work, somehow.
Yes, you can select the text, then run your macro - which you could assign to a keyboard shortcut (for which Graham has provided a link).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
A simple math question markg2 Excel 6 03-01-2014 11:10 AM
Editing styles with macros/VBA: a simple question Simple Mail Merge Question Ethanflux Mail Merge 1 09-29-2013 07:21 PM
Editing styles with macros/VBA: a simple question Simple question about line space danezcou3 Word 1 04-21-2013 05:38 AM
Editing styles with macros/VBA: a simple question Simple Question, difficult task... Jshopping Word 4 01-19-2011 03:04 PM
Simple Envelope Question.... cmcneill Word 0 08-17-2009 05:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft