[Solved] Macro works manually but not when hyperlinked

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
JamesSmith32
Posts: 10
Joined: Wed Jan 22, 2020 12:55 pm

[Solved] Macro works manually but not when hyperlinked

Post by JamesSmith32 »

I have this Macro

Code: Select all

Sub ScrollToAvailableColumn( Optional iRowIndex )

Dim oDoc As Object      : oDoc    = ThisComponent
Dim sCell 
Dim oController
oController = oDoc.getCurrentController() 
Dim oSheet As Object    : oSheet  = oDoc.CurrentController.ActiveSheet
sCell = oSheet.getCellByPosition(2, 2)
oController.select(sCell)

    If IsMissing( iRowIndex ) Then iRowIndex = oDoc.CurrentSelection.RangeAddress.StartRow
    Dim oRow As Object   : oRow = oSheet.Rows.getByIndex( iRowIndex )
    Dim oRanges As Object   : oRanges = oRow.queryContentCells(_
    com.sun.star.sheet.CellFlags.VALUE OR _
    com.sun.star.sheet.CellFlags.DATETIME OR _
    com.sun.star.sheet.CellFlags.STRING OR _
    com.sun.star.sheet.CellFlags.FORMULA)
   
   	Dim lColumn As Long
    Dim lCount As Long      : lCount  = oRanges.getCount()
    If lCount > 0 Then        lColumn    = oRanges.getByIndex( lCount - 1 ).RangeAddress.EndColumn + 1
    Dim oCell As Object     : oCell   = oRow.getCellByPosition( lColumn + 1, 0 )
oController.select( oCell )

End Sub
When I run it manually it works fine, just as I want it to. However, when I run it with a hyperlink or a pushbutton it wont work.

Code: Select all

=HYPERLINK("vnd.sun.star.script:standard.scroll.scrolltoavailablecolumn?language=Basic&location=document"; "Click here to Scroll" )
Image

How can I get this to work with Hyperlink?

Thanks
Last edited by JamesSmith32 on Mon Feb 03, 2020 1:28 pm, edited 1 time in total.
Open Office 4.1.7 Windows 10
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro works manually but not when hyperlinked

Post by JeJe »

Its easier for people to look at the problem if you post the document and give a more specific description than just it won't work.

if you add the msgbox line you can see that RangeAddress.StartRow returns a string of the hyperlink target macro when the hyperlink is clicked not a row number.

Code: Select all

  If IsMissing( iRowIndex ) Then iRowIndex = oDoc.CurrentSelection.RangeAddress.StartRow
    msgbox irowindex

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro works manually but not when hyperlinked

Post by Villeroy »

Inspect your variables. iRowIndex is not a number nor missing. It is the URL of the calling hyperlink.

See download/file.php?id=27213
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JamesSmith32
Posts: 10
Joined: Wed Jan 22, 2020 12:55 pm

Re: Macro works manually but not when hyperlinked

Post by JamesSmith32 »

Yes, fixed, thanks both of you.
Open Office 4.1.7 Windows 10
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: [Solved] Macro works manually but not when hyperlinked

Post by arfgh »

around this, and hyperlinks... what i am unable to get to works is this hyperlink added from basic

Code: Select all

=HYPERLINK("vnd.sun.star.script:standard.scroll.scrolltoavailablecolumn?language=Basic&location=document"; "Click here to Scroll"
problem is i cant set the 'tooltip' as you did on that example ^^
some idea about ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Post Reply