Ask Your Question

Macros to find an image inline of text [closed]

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

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

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

echo8hink gravatar image

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

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

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

DDorin gravatar image

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

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 = ""

    ' 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.

        ' 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


    Next i

End Function
edit flag offensive delete link more

Question Tools

1 follower


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

Seen: 95 times

Last updated: Feb 03 '19