[Solved] Macro with Keys sequence

Creating a macro - Writing a Script - Using the API

[Solved] Macro with Keys sequence

Postby pasaico » Wed Jan 03, 2018 4:16 pm

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   Expand viewCollapse view
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
pasaico
 
Posts: 2
Joined: Wed Jan 03, 2018 4:10 pm

Re: MACRO with Keys sequence

Postby RoryOF » Wed Jan 03, 2018 6:51 pm

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.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29608
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: MACRO with Keys sequence

Postby Lupp » Wed Jan 03, 2018 6:59 pm

-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   Expand viewCollapse view
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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2543
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: MACRO with Keys sequence

Postby Zizi64 » Wed Jan 03, 2018 7:21 pm

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; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.8; AOO4.1.6
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.
User avatar
Zizi64
Volunteer
 
Posts: 8389
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: MACRO with Keys sequence

Postby pasaico » Thu Jan 04, 2018 12:16 pm

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   Expand viewCollapse view
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
pasaico
 
Posts: 2
Joined: Wed Jan 03, 2018 4:10 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests