2

I have trouble making hyperlink within macro.

For example just create empty spreadsheet and create another sheet within so we have 2 empty sheets.

In Sheet1 A:1 just paste =HYPERLINK("#Sheet2")

For A:3 create macro and execute it

Sub TestMacro
    dim document as object
    oSheet = thiscomponent.sheets.getByName("Sheet1")
    oCell = oSheet.getCellRangeByName("$A$3")
    xx="=HYPERLINK(""#Sheet2"")"
    oCell.setString(xx)
End Sub

So sheet1 now have something on cell A1 and A3. the both should be link but just A1 works. If jou press CTRL+click on Sheet1 A1 the Sheet2 is selected. If you press CTRL+click on Sheet1 A3 nothing happens

I tested ou xubuntu 18.04LTS LibreOffice Version: 6.0.7.3 Build ID: 1:6.0.7-0ubuntu0.18.04.10

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
eSlavko
  • 348
  • 3
  • 12
  • After upgrading to Version: 6.3.3.2 Build ID: 1:6.3.3-0ubuntu0.18.04.1~lo1 the issue still remain – eSlavko Nov 30 '19 at 16:29

1 Answers1

1

For functions and calculations, set the cell formula instead of a literal string value.

oCell.setFormula(xx)
Jim K
  • 12,824
  • 2
  • 22
  • 51
  • It may worth to mention that if you have LibreOffice localized in other languages the functions must be set in english with setFormula(...) (i. e. setting =HYPERLINK instead of =HIPERVINCULO that would be in spanish). – Paco Abato Jul 15 '22 at 16:39