0

I cannot figure out (or find an example) how to perform the following simple thing in the LibreOffice Calc 6.2:

I have a drawing shape (e.g. a simple rectangle) in a sheet (call it ShapeA) and a textbox shape in another sheet (call it TextboxB). I want to do the following: when I click on the ShapeA, the TextboxB must appear on the screen (without changing the current sheet, maybe in a dialog box) and then be closed with a mouse click.

I guess the macro associated with ShapeA could look something like this:

Sub Main
oDrawPage = ThisComponent.getDrawPage()
oTb = oDrawPage.getByName("TextBoxB")
oTb.show()
End Sub

Could someone advise what I should put into this macro to accomplish the described task?

UPDATE: What I want to accomplish ( in reply to Jim K.).

I have a very cluttered diagram with many shapes. Each shape has some textual information associated with it. There is not enough space on each shape or around it to contain this info. So there is must be a way to display this info about each shape. Also this information should be displayed in a preformatted way (it contains code and other structured info).

My plan is to create a textbox with the relevant information for each diagram shape, place these textboxes in other sheet and have a possibility, when viewing diagram, to click on any shape and view the associated info in the poped up textbox without leaving the diagram, and then close the textbox with a simple action (e.g. by clicking on it).

Does this task sound feasible to be realized with the LO's shapes and macros?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Al Berger
  • 1,048
  • 14
  • 35
  • Do you want to do this so that the text can be edited? If so, you could show a dialog box with text from the other text box, and when the dialog is closed, update the text box on the other sheet. Or, maybe you want to cut and paste the shape to the current sheet and then move it back to the other sheet when the macro finishes. Maybe it would help to tell more about the overall goal, because your question sounds contradictory as stated - showing the shape on the sheet without showing the sheet seems like it should be impossible. – Jim K Apr 23 '20 at 17:44
  • Hello Jim K, thank you for your comment. I updated the question. Please check for the additional info. – Al Berger Apr 23 '20 at 19:48
  • The additional information was helpful; thank you. – Jim K Apr 24 '20 at 18:03

1 Answers1

1

How about this: Put everything on the same sheet but keep the text boxes hidden until needed.

Use the following code adapted from https://ask.libreoffice.org/en/question/93050/how-can-i-hideshow-a-shape-of-my-spreadsheet-using-a-macro/.

Sub ShapeClickedA
    ShowHideShape("TextBoxA")
End Sub
Sub ShapeClickedB
    ShowHideShape("TextBoxB")
End Sub

Sub ShowHideShape(shapeName As String)
    oDrawPage = ThisComponent.getSheets().getByName("Sheet1").getDrawPage()
    For iShape = 0 To oDrawPage.Count - 1
        oShape = oDrawPage.getByIndex(iShape)
        If oShape.Name = shapeName Then
            If oShape.Visible Then
                oShape.Visible = 0  'Not Visible
            Else
                oShape.Visible = 1  'Visible
            End If
        End If
    Next iShape
End Sub

If you haven't yet, set the names of the text boxes by right-clicking and choosing Name... Then right click on both ShapeA and TextBoxA and assign the macro ShapeClickedA. Do likewise for other pairs of shapes. The result works like this:

  1. Before anything is clicked.

no text boxes displayed

  1. Click on ShapeA. (To close it again, click on either ShapeA or TextBoxA). ShapeB functions similarly.

TextBoxA displayed

  1. It's also possible to display both at the same time.

TextBoxA and TextBoxB displayed

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • Your variant is even better since it allows to edit textboxes without leaving the main diagram. Thanks for the answer. – Al Berger Apr 25 '20 at 11:46