Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2017, 11:15 AM
Karin Carlson Karin Carlson is offline How to change properties of selected shapes Windows 10 How to change properties of selected shapes Office 2016
Novice
How to change properties of selected shapes
 
Join Date: Aug 2017
Posts: 4
Karin Carlson is on a distinguished road
Post How to change properties of selected shapes

I've been looking all over to find some code that will allow me to alter the properties of one or more shapes that I manually select.

In plain English, this is what I would like it to do:

for the selected shape(s), change the following properties:
line width and color
fill color
size (width/height)
shape type (e.g., rectangle to circle)




This seems like it would be easy but none of the code I've tried seems to work at all.

(For clarification, I'd like to do this for both inline shapes and shapes that are "floating", but I realize that they are different in Word, so I don't need to do these at the same time or with the same code.)

Help would be greatly appreciated!!

Karin
Reply With Quote
  #2  
Old 08-09-2017, 03:21 PM
macropod's Avatar
macropod macropod is offline How to change properties of selected shapes Windows 7 64bit How to change properties of selected shapes 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

Assuming you're referring to autoshapes, all of this is possible with VBA but, without knowing precisely what you want to change, it's impossible to supply the code. As a demo:
Code:
Sub Demo()
With ActiveDocument.Shapes(1)
  .AutoShapeType = msoShapeOval 'msoShapeRectangle
  .Fill.ForeColor.RGB = RGB(255, 255, 0)
  .Fill.BackColor.RGB = RGB(127, 0, 0)
  .Fill.TwoColorGradient msoGradientFromCenter, 2
  .Fill.Transparency = 0.25
  .Line.Weight = 2
  .Height = InchesToPoints(1.25)
  .Width = InchesToPoints(1.5)
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-09-2017, 03:58 PM
Karin Carlson Karin Carlson is offline How to change properties of selected shapes Windows 10 How to change properties of selected shapes Office 2016
Novice
How to change properties of selected shapes
 
Join Date: Aug 2017
Posts: 4
Karin Carlson is on a distinguished road
Post Thanks, but how to target selected shape?

Hi there- thanks for that. I had bits and pieces of that, but have two more questions:

1 - Because of the index for the shape, it's only doing the first shape in the document, which is (I assume) the first shape in the collection. How can I select a shape or multiple shapes and then run the macro and have it affect only the shapes I select?

2 - I can't find a method to apply a text (paragraph) style to the text inside a shape.

Thanks!
Reply With Quote
  #4  
Old 08-09-2017, 04:11 PM
macropod's Avatar
macropod macropod is offline How to change properties of selected shapes Windows 7 64bit How to change properties of selected shapes 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

For a single selected shape you could change:
With ActiveDocument.Shapes(1)
to:
With Selection.ShapeRange(1)
You could, of course, change the index # to refer to the 2nd, 3rd, etc. Shape in the document or selection, as appropriate. For multiple shapes, you'd need to implement a loop.

To work with text in a shape, refer to its .TextFrame.TextRange property.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-09-2017, 09:15 PM
Karin Carlson Karin Carlson is offline How to change properties of selected shapes Windows 10 How to change properties of selected shapes Office 2016
Novice
How to change properties of selected shapes
 
Join Date: Aug 2017
Posts: 4
Karin Carlson is on a distinguished road
Default

Ah, brill, thanks. I am mostly okay with figuring out properties, but the ShapeRange thing is new. Thanks so much for your speedy reply.
Reply With Quote
  #6  
Old 08-09-2017, 09:42 PM
Karin Carlson Karin Carlson is offline How to change properties of selected shapes Windows 10 How to change properties of selected shapes Office 2016
Novice
How to change properties of selected shapes
 
Join Date: Aug 2017
Posts: 4
Karin Carlson is on a distinguished road
Smile yippee!

Thank you very much for your help -- for the benefit of others and for posterity, here's what I am using. I have two sub routines. (Added a 3rd which includes a loop so it does all the selected shapes.)

1 - Changes a selected shape with a number in it to a cute little red circle .18" h/w, and applies a style (Stepcircles) to the number inside the circle.

Code:
Sub redCircle()
With Selection.ShapeRange(1)
    .AutoShapeType = msoShapeOval
    .Fill.ForeColor.RGB = RGB(255, 255, 255)
    .Fill.BackColor.RGB = RGB(255, 255, 255)
    .Line.Weight = 1
    .Line.ForeColor.RGB = RGB(255, 0, 0)
    .Height = InchesToPoints(0.18)
    .Width = InchesToPoints(0.18)
    .TextFrame.TextRange.Style = "Stepcircles"
    .TextFrame.MarginBottom = 0
    .TextFrame.MarginRight = 0
    .TextFrame.MarginTop = 0
    .TextFrame.MarginLeft = 0
    
    End With
End Sub
2 - Changes a selected shape to a red rectangle that has a 1pt border.

Code:
Sub redOutlineOneRectangle()
    With Selection.ShapeRange(1)
        .AutoShapeType = msoShapeRectangle
        .Line.Weight = 1
        .Line.ForeColor.RGB = RGB(255, 0, 0)
        End With

End Sub
3 - Same as #1, but will do all the shapes in the selection.

Code:
Sub redCircles()

Dim allShapes As ShapeRange
Dim myShape As Shape

Set allShapes = Selection.ShapeRange

For Each myShape In allShapes
    
  
With myShape
    .AutoShapeType = msoShapeOval
    .Fill.ForeColor.RGB = RGB(255, 255, 255)
    .Fill.BackColor.RGB = RGB(255, 255, 255)
    .Line.Weight = 1
    .Line.ForeColor.RGB = RGB(255, 0, 0)
    .Height = InchesToPoints(0.18)
    .Width = InchesToPoints(0.18)
    .TextFrame.TextRange.Style = "Stepcircles"
    .TextFrame.MarginBottom = 0
    .TextFrame.MarginRight = 0
    .TextFrame.MarginTop = 0
    .TextFrame.MarginLeft = 0
    
    End With
    
Next myShape
End Sub

Last edited by Karin Carlson; 08-09-2017 at 10:07 PM. Reason: added another code example with loop
Reply With Quote
Reply

Tags
shape, shapes



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change properties of selected shapes Macro to change all text color to black in all docx files in a selected folder joewoods Word VBA 13 05-16-2016 06:29 PM
How to change properties of selected shapes Margin change for selected text in Word 7 Richtriebe Word 4 03-14-2016 11:57 AM
How to change properties of selected shapes Change ComboBox Properties ll4u76 Word VBA 1 03-31-2012 05:08 AM
Change object properties by clicking PopOnTheAir PowerPoint 7 03-16-2012 02:13 PM
Change cell color everytime a value is selected in dropdown list angelica_gloria Excel 4 01-27-2012 06:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:17 AM.


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