Help resolve an issue using macro

can you help me reviewig my macro code please?

Sub ChangeImage
    Dim oDoc As Object
    Dim oSheet As Object
    Dim oBull As Object
    Dim oBear As Object
    Dim oBull1 As Object
    Dim oBear1 As Object
    Dim oCell As Object

    oDoc = ThisComponent
    oSheet = oDoc.Sheets(0)
    oBull = oSheet.DrawPage.getByName("Bull")
    oBear = oSheet.DrawPage.getByName("Bear")
    oBull1 = oSheet.DrawPage.getByName("Bull1")
    oBear1 = oSheet.DrawPage.getByName("Bear1")
    oCell = oDoc.Sheets(0).getCellRangeByName("H33")

    If oCell.Value > 0 Then
        oBull.Visible = True
        oBear.Visible = False
        oBull1.Visible = False
        oBear1.Visible = True
    ElseIf oCell.Value < 0 Then
        oBull.Visible = False
        oBear.Visible = True
        oBull1.Visible = True
        oBear1.Visible = False
    End If
End Sub

what i am trying to do:

i go a H33 cell that give a result positive or negative
I have 2 boxes:
right box image 1
left box image 2

i have if H33 give negative number to show Image 1 to the right and imag2 to the left
and vis versa if H33 is positive

now when i run the code it state:
“BASIC runtime error.
Property or method not found: getByName.”

why is that hope to hear soon from the community

besr regads,
NGU

Yes, the method getByName not exists in object DrawPage, you try with:

	draw_page = sheet.DrawPage
	
	For Each shape In draw_page
		Select Case shape.Name
			Case "Bull"
				oBull = shape
			Case "Bear"
				oBear = shape
			Case "Bull1"
				oBull1 = shape
			Case "Bear1"
				oBear1 = shape
		End Select
	Next 

And the rest of your code.

1 Like

gonna try to do that thanks a ton