[Solved] Macro with Keys sequence

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
pasaico
Posts: 2
Joined: Wed Jan 03, 2018 4:10 pm

[Solved] Macro with Keys sequence

Post by pasaico »

Hi guys,

i have recorder a macro with this sequence keys;

press F2
press SPACE
press RETURN

but not work, not record nothing keys.

This sequence make a text http://foo.everthing.com in a HYPERLINK URL clickable

Can you help me?

Code: Select all

sub Link
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$J$1"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$J$1"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())


end sub
Last edited by Hagar Delest on Thu Jan 04, 2018 2:31 pm, edited 1 time in total.
Reason: tagged solved
OpenOffice 4.1.4 on Windows 10 x64bit
User avatar
RoryOF
Moderator
Posts: 34611
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: MACRO with Keys sequence

Post by RoryOF »

The OpenOffice macro recorder givs only an outline; one has to add in, by hand programming, the detail of required system calls. These are detailed in the OO BASIC guide and the OO API documentation, both linked off
http://www.openoffice.org/api/
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: MACRO with Keys sequence

Post by Lupp »

-1- The macro recorder isn't a key logger.
-2- The sequence of key actions you described wouldn't result in a recorded macro like the one you posted.
-3- What did you do to get that text (e.g.) as simple text without the link?
-4- You won't succeed with a recorded macro, most likely.
-5- A macro actually capable of creating a clickable link from simple text would need to read that text and to create a "TextField" of it.
-6- No dispatcher command available for the task afaik.

You may select the range where your unclickable URL are and try this BASIC Sub:

Code: Select all

Sub makeClickable()
theDoc   = ThisComponent
theRange = theDoc.CurrentSelection
If NOT theRange.SupportsService("com.sun.star.sheet.SheetCellRange") Then 
   MsgBox("Sub ""makeClickable"" only working on simple ranges!")
   Exit Sub
End If
With theRange.RangeAddress
   theSheet = theDoc.Sheets(.Sheet)
   For x = .StartColumn To .EndColumn
    For y = .StartRow To .EndRow
     theCell                 = theSheet.GetCellByPosition(x, y)
     theUrlString            = theCell.String
     urlField                = ThisComponent.createInstance("com.sun.star.text.TextField.URL")
     urlField.URL            = ConvertToURL(theUrlString)
     If urlField.URL="" Then Goto next_y
     urlField.Representation = theUrlString
     theCell.String          = ""
     theText                 = theCell.GetText
     theText.insertTextContent(theText.createTextCursor(), urlField, False)
     next_y:
   Next y
  Next x
End With
End Sub
There are no tests concerning the question if the string found in a cell can at all be converted to a clickable URL.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: MACRO with Keys sequence

Post by Zizi64 »

press F2
press SPACE
press RETURN

but not work, not record nothing keys.
Use the Menu items for recording macros.
It is better to WRITE your macros instead of the recording - because the macro recorder has a limited capability.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
pasaico
Posts: 2
Joined: Wed Jan 03, 2018 4:10 pm

Re: MACRO with Keys sequence

Post by pasaico »

Lupp wrote:-1- The macro recorder isn't a key logger.
-2- The sequence of key actions you described wouldn't result in a recorded macro like the one you posted.
-3- What did you do to get that text (e.g.) as simple text without the link?
-4- You won't succeed with a recorded macro, most likely.
-5- A macro actually capable of creating a clickable link from simple text would need to read that text and to create a "TextField" of it.
-6- No dispatcher command available for the task afaik.

You may select the range where your unclickable URL are and try this BASIC Sub:

Code: Select all

Sub makeClickable()
theDoc   = ThisComponent
theRange = theDoc.CurrentSelection
If NOT theRange.SupportsService("com.sun.star.sheet.SheetCellRange") Then 
   MsgBox("Sub ""makeClickable"" only working on simple ranges!")
   Exit Sub
End If
With theRange.RangeAddress
   theSheet = theDoc.Sheets(.Sheet)
   For x = .StartColumn To .EndColumn
    For y = .StartRow To .EndRow
     theCell                 = theSheet.GetCellByPosition(x, y)
     theUrlString            = theCell.String
     urlField                = ThisComponent.createInstance("com.sun.star.text.TextField.URL")
     urlField.URL            = ConvertToURL(theUrlString)
     If urlField.URL="" Then Goto next_y
     urlField.Representation = theUrlString
     theCell.String          = ""
     theText                 = theCell.GetText
     theText.insertTextContent(theText.createTextCursor(), urlField, False)
     next_y:
   Next y
  Next x
End With
End Sub
There are no tests concerning the question if the string found in a cell can at all be converted to a clickable URL.
Thank you Lupp, this basic SUB it's ok and work great.
I to make clickable, I had to do the procedure manually
F2
SPACE
RETURN

Thank you LUPP

pasaico
OpenOffice 4.1.4 on Windows 10 x64bit
Post Reply