OberonPlace.com Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-05-2018, 03:47
ager ager is offline
Member
 
Join Date: Jul 2010
Location: Russia
Posts: 44
Default Count of shapes

For example, I have two selected any shapes.

Code:
Sub test()
Dim s as shape
  Set s=ActiveShape
  ActiveDocument.ClearSelection
  'How to know count of the shapes in 's'?
End Sub
How to know count of the shapes in 's'?

Last edited by ager; 08-05-2018 at 03:50.
Reply With Quote
  #2  
Old 11-05-2018, 18:37
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 428
Default

Sorry I don't understand the question. If you have used ActiveDoucment,ClearSelection then the shape count should be 0.

Code:
Sub count()

MsgBox ActiveSelection.Shapes.count

End Sub
Note this treats grouped object as a single shape. The following makes a duplicate of the selection, ungroups it and counts all the shapes before deleting the duplicate.

Code:
Sub CountSelectedShapes()

Dim s As Shape
Dim n As Double

If ActiveSelection.Shapes.count > 0 Then
    
    Set s = ActiveSelection.Duplicate
    s.UngroupAll
    n = s.Shapes.count
    s.Delete
    
    MsgBox "The number of shapes is: " & n, vbInformation, "Active Selection Count"
    
Else

    MsgBox "Please select some shapes.", vbExclamation, "Oops!"

End If

End Sub

Last edited by knowbodynow; 11-05-2018 at 18:48.
Reply With Quote
  #3  
Old 16-05-2018, 22:00
ager ager is offline
Member
 
Join Date: Jul 2010
Location: Russia
Posts: 44
Default

Quote:
Originally Posted by knowbodynow View Post
If you have used ActiveDoucment,ClearSelection then the shape count should be 0.
No, the object "s" continues to exist. I do not delete it. So, the question is how to determine how many shapes are contained in the object "s".
Reply With Quote
  #4  
Old 17-05-2018, 02:29
shark shark is offline
Senior Member
 
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 132
Default

use ActiveSelectionRange
Code:
Sub test()
Dim sr as ShapeRange
  Set sr = ActiveSelectionRange
  ActiveDocument.ClearSelection
  MsgBox sr.Count
End Sub
Reply With Quote
  #5  
Old 17-05-2018, 05:27
ager ager is offline
Member
 
Join Date: Jul 2010
Location: Russia
Posts: 44
Default

Thanks for the answers. But my function works with objects which type is "Shape", not "ShapeRange". As I understand, the object "Shape" can not give the information about number of shapes it really contains.

I discovered that object "Shape" can contain only one shape. If we have two (or more) selected shapes and execute this code, only one shape will be copied and pasted:
Code:
Sub test()
Dim s as Shape
  Set s=ActiveShape
  ActiveDocument.Copy
  ActiveDocument.ClearSelection
  ActiveLayer.Paste
End Sub

Last edited by ager; 17-05-2018 at 21:29.
Reply With Quote
  #6  
Old 18-05-2018, 05:18
shark shark is offline
Senior Member
 
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 132
Default

Quote:
Originally Posted by ager
I discovered that object "Shape" can contain only one shape
No. Object "shape" can be a "group" or "powerclip" and contain other objects. If you have selected some shapes and want to work with them, then use ShapeRange
Reply With Quote
Reply


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
Count shapes on Pritable are gebp CorelDRAW/Corel DESIGNER VBA 3 31-10-2011 19:02
X5 Documents.Count error knowbodynow CorelDRAW/Corel DESIGNER VBA 1 04-05-2010 22:30
count colors in PP Jeff Harrison Corel Photo-Paint VBA 0 17-12-2008 02:38
PP12 tools count = 0 Michael Cervantes Corel Photo-Paint VBA 0 29-05-2004 23:09
looping until documents.count = 0 bbolte CorelDRAW/Corel DESIGNER VBA 18 18-02-2003 15:03


All times are GMT -5. The time now is 17:35.


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