Ask Your Question
0

Macros to find an image inline of text [closed]

asked 2019-02-02 16:40:49 +0200

DDorin gravatar image

How can I determine if a paragraph in my text document contains images using Basic macros? Thank you!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by DDorin
close date 2019-02-06 04:43:12.889360

2 Answers

Sort by » oldest newest most voted
0

answered 2019-02-02 20:15:36 +0200

echo8hink gravatar image

updated 2019-02-02 20:17:40 +0200

See Andrew Pitonyak's text's. Useful Macro Information 7.16.4 and 7.16.5 link here.

His documentation and examples of Oo and LO macro use are a valuable resource for macro users.

edit flag offensive delete link more
0

answered 2019-02-03 21:18:41 +0200

DDorin gravatar image

updated 2019-02-03 21:20:37 +0200

Thank you echo8hink for a very useful answer! I have found a solution.

Function inlineShapesStyles(ByVal styleName As String)

    Dim oVCurs As Object ' The view cursor
    Dim oTCurs As Object ' The text cursor
    Dim oText  As Object ' Text object that contains the view cursor

    sTContentService = "com.sun.star.text.TextContent"

    ' The view cursor knows where a line ends
    oVCurs = ThisComponent.CurrentController.getViewCursor()

    ' The text object that contains the view cursor
    oText = oVCurs.Text

    ' Require a text cursor so that you know where the paragraph ends.
    ' The view cursor is not a paragraph cursor.
    oTCurs = oText.createTextCursorByRange(oVCurs) 
    oTCurs.gotoStart(False) ' Begins the search at the start of the document

    ' Iterates paragraphs
    For i = 0 To ThisComponent.ParagraphCount
        inlineTextShape = False

        ' Require a text cursor so that you know where the paragraph ends.
        oTCurs.gotoStartOfParagraph(False)
        oTCurs.gotoEndOfParagraph(True)

        ' Enumerates graphics (does NOT work to enumerate text fields)
        oEnum = oTCurs.createContentEnumeration(sTContentService)
        Do While oEnum.hasMoreElements()
            oSect = oEnum.nextElement()

            If oSect.ShapeType = "FrameShape" Then
                'If oSect.ImplementationName = "SwXTextGraphicObject" Then ' optional
                oTCurs.ParaStyleName = styleName
                msgbox "Shape found"
                Exit Do
            End If
        Loop

        oTCurs.gotoNextParagraph(false)

    Next i

End Function
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-02-02 16:40:49 +0200

Seen: 38 times

Last updated: Feb 03