need help but situation has multiple challenges

i want to do indexing in my designs but sometime design has 10 pages sometime 100 and sometime its 500

i will wrote indexing according to the pages for example i have 10 pages book and now i have wrote all the index example are below

abc

def

ghi

jkl

mno

pqr

stu

wvx

yz1

234

now i will create a box of 15mm X10mm height box with a cut mark of 2 mm in bottom right of the box and

add all text to box according to the box for example 1st index in top 1st box, 2nd index in 2nd box etc.

now i group all box with index.

now i have 10 box with index grouped.

now i move them to the bottom right  side according to the series

last step i paste 1 by 1 on different pages. 1st index on 1st page, 2nd on 2nd page and soo on

just like this i want macro

Parents Reply
  • paraggoyal said:

    I think the problem is that my macro aligns and then groups text+rectangle, but is not expecting the rectangle to already be part of a group. That's what you are trying to have it work with now.

    Here is a modified version of the macro that does not look for rectangles. Instead if uses all shapes (including groups) that are not text shapes.

    If the shape that it is using is a group, then the text will be aligned to the entire group. If each of your cut marks is grouped with a rectangle, and on the edge of that rectangle as in your example, then that would not be a problem.

    Sub text_paras_to_shapes()
    Dim sr1_index As Long
    Dim sr1 As ShapeRange
    Dim sr2 As New ShapeRange
    Dim sr3 As New ShapeRange
    Dim para_count As Long
    Dim counter_1 As Long
    Dim s2 As Shape
    Dim tr As TextRange

        Optimization = True
        ActiveDocument.BeginCommandGroup "text paras to shapes"
        EventsEnabled = False
        On Error GoTo ErrHandler
           
        Set sr1 = ActiveSelectionRange
        If sr1.Count = 0 Then
            MsgBox "Nothing is selected."
        GoTo ExitSub
        End If
        
        sr1_index = 1
        Do
            If sr1(sr1_index).Type = cdrTextShape Then
                sr2.Add sr1(sr1_index)
                sr1.Remove (sr1_index)
            End If
            sr1_index = sr1_index + 1
        Loop Until sr1_index > sr1.Count
        
        If sr2.Count = 0 Then
            MsgBox "No text shape was found in the selection."
            GoTo ExitSub
        Else
            If sr2.Count > 1 Then
                MsgBox "More than one text shape was found in the selection."
                GoTo ExitSub
            End If
        End If
        
        para_count = sr2(1).Text.Story.Paragraphs.Count
        If para_count > sr1.Count Then
            MsgBox "The number of paragraphs in the text shape (" & para_count & ") is more than the number of rectangles (" & sr1.Count & ") in the selection."
            GoTo ExitSub
        End If
            
        sr1.Sort "@shape1.top>@shape2.top"
        
        For counter_1 = 1 To para_count
            Set tr = sr2(1).Text.Story.Paragraphs(counter_1)
            Set s2 = ActiveDocument.ActiveLayer.CreateArtisticText(0, 0, tr.Text, , , tr.Font, tr.Size, tr.Bold, tr.Italic, tr.Underline)
            s2.Fill = tr.Fill
            s2.CenterX = sr1(counter_1).CenterX
            s2.CenterY = sr1(counter_1).CenterY
            sr3.RemoveAll
            sr3.Add s2
            sr3.Add sr1(counter_1)
            sr3.Group
        Next counter_1
        
        ActiveSelection.Shapes.All.RemoveFromSelection

    ExitSub:
        Optimization = False
        EventsEnabled = True
        Application.Refresh
        ActiveDocument.EndCommandGroup
        Exit Sub

    ErrHandler:
        MsgBox "Error occurred: " & Err.Description
        Resume ExitSub
    End Sub

    Before running macro:


    After running macro:

Children