OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Thread Tools Search this Thread Display Modes
Old 24-06-2016, 17:38
LaffRiot LaffRiot is offline
Junior Member
Join Date: Jun 2008
Posts: 14
Default Insert shape at a specified location in shaperange

Is it possible to add a new shape to a shaperange at a specified location?

for example I have 10 units of artistic text added to shaperange sr.
I want to create a new unit of artistic text at location 5 in the shaperange - using an input box to prompt for the text and insert location.

at the moment I am adding the shaperange to another shaperange up to the point of insertion. Creating the new artistic text and adding it. Then resuming from the breakpoint to the end of the original shaperange. It works - but it is very clunky. I am hoping there is an elegant solution.

Thanks for taking a look.
Reply With Quote
Old 04-12-2016, 01:13
shelbym's Avatar
shelbym shelbym is offline
Senior Member
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,782
Blog Entries: 11
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Order ShapeRange

Create a Function that places the Shape in the position you wish in the ShapeRange and then have it return that ShapeRange. Here is an example of the function. If your position is greater then the shapes selected it just adds the new shape to the end of the ShapeRange:
Function PlaceShapeInShapeRange(sr As ShapeRange, s As Shape, iPos As Long) As ShapeRange
    Dim srOrdered As New ShapeRange
    Dim i As Long
    For i = 1 To sr.Shapes.Count
        If i = iPos Then srOrdered.Add s
        srOrdered.Add sr(i)
    Next i
    'If the position is greater than the number of shapes in the shape range just add it to the end
    If iPos > sr.Shapes.Count Then srOrdered.Add s
    Set PlaceShapeInShapeRange = srOrdered
End Function
Here is an example of how you might use the function, make sure you have more than 5 items selected or it will just put it to the end and it will not change to red because it is not in the 5th position.
Sub TestingPlaceShapeInShapeRange()
    Dim sr As ShapeRange
    Dim sText As Shape
    Set sr = ActiveSelectionRange
    Set sText = ActiveLayer.CreateArtisticText(0, 0, "Where am I in Order?", , , "Ariel")
    Set sr = PlaceShapeInShapeRange(sr, sText, 5)
    If sr.Shapes.Count >= 5 Then sr(5).Fill.ApplyUniformFill CreateRGBColor(255, 0, 0)
End Sub
Best of Luck,

Reply With Quote
Old 06-05-2017, 18:21
LaffRiot LaffRiot is offline
Junior Member
Join Date: Jun 2008
Posts: 14

Shelby - thank you for the solution.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Shape from File davidpmp Macros/Add-ons 3 02-01-2012 01:07
shape insert macro with lots of options gorgo CorelDRAW/Corel DESIGNER VBA 2 28-04-2011 21:42
Can a macro be run from different location aakkaarr CorelDRAW/Corel DESIGNER VBA 6 31-05-2010 16:57
File location diwin CorelDRAW/Corel DESIGNER VBA 5 01-07-2007 12:46
how do i define a save location? cristov CorelDRAW/Corel DESIGNER VBA 4 28-10-2005 20:03

All times are GMT -5. The time now is 10:44.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com