Nov 03 2023 07:12 PM
Hi!
I'm looking for a way to, when selecting a text box/shape, be able to just apply a macro to format it, to a specific background color, with no border, and some basic shadow.
I can't seem to find a way to do that to a random text box, meaning, I would not have the object name to refer it in the macro.
So, I need the macro identify the object that I'm selecting and then apply what I want to it.
Thanks in advance.
Nov 04 2023 09:49 AM
Why not simply create a text box formatted the way you want and add it to your Text Boxes Gallery?
Nov 04 2023 11:02 AM
Nov 04 2023 11:21 AM
Nov 04 2023 11:28 AM
Nov 04 2023 02:50 PM
Nov 04 2023 02:56 PM
Nov 04 2023 06:02 PM - edited Nov 04 2023 06:07 PM
Solution
Here is an example:
.
Sub ShapeSelectedFormat()
'
' Charles Kenyon 4 November 2023
'
' See https://learn.microsoft.com/en-us/office/vba/api/word.shape
'
With Selection.ShapeRange(1)
.Fill.ForeColor.ObjectThemeColor = wdThemeColorAccent2
.AutoShapeType = msoShapeOval
End With
End Sub
Here is the support page on the Shape Object.
https://learn.microsoft.com/en-us/office/vba/api/word.shape
You can choose the attributes you want to change within the With structure. They are listed in the support article.
You could attach your macro to a keyboard shortcut and/or a QAT button. Those should be stored in the same template that holds your macro.
Word has two Shape collections, Shapes and InLineShapes. I am not sure this will work with both but you are welcome to try it.