| View previous topic :: View next topic |
| Author |
Message |
rebelxt OOo Enthusiast


Joined: 10 Dec 2006 Posts: 114 Location: StLouis
|
Posted: Sat Mar 03, 2007 9:06 am Post subject: Following a hyperlink |
|
|
A way to follow a hyperlink from an OOo Basic macro was given in this thread by ms777:
http://www.oooforum.org/forum/viewtopic.phtml?t=49839
| Quote: |
the following is equivalent to the .Hyperlinks(1).Follow in Word:
| Code: |
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
oDisp.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:OpenHyperlinkOnCursor", "", 0, Array())
|
|
Does this work in Calc? If so, what are the initializaton requirements? What do you put in Array()? |
|
| Back to top |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Sat Mar 03, 2007 4:34 pm Post subject: |
|
|
Did you notice the later post by ms777 in the same thread? He published code to read uno services available in ThisComponent and print the output to a spreadsheet.
The service you mention is available in a spreadsheet. Array() is usually empty.
| ms777 wrote: | | I have not yet fount a way to identfy the source code position of the various dispatches. This would allow to identify the parameters. Documentation is really a mess here |
_________________ search forum by month |
|
| Back to top |
|
 |
rebelxt OOo Enthusiast


Joined: 10 Dec 2006 Posts: 114 Location: StLouis
|
Posted: Sat Mar 03, 2007 7:25 pm Post subject: |
|
|
| Sorry, I didn't ask enough questions. There is a hyperlink in a cell, which is the selected cell on the currently active sheet... Those two statements don't cause the hyperlink to be followed. I'm obviously missing something. What? |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Sun Mar 04, 2007 9:47 am Post subject: |
|
|
This is hard to solve since we have to use dispatches, which is an ugly workaround for missing API-features. The problem is that there is no hyperlink selected when you dispatch ".uno:OpenHyperlinkOnCursor".
This does not help very much, but it demonstrates the problem:
| Code: |
REM ***** BASIC *****
Sub Main
oView = thisComponent.getCurrentController
oCell = thisComponent.sheets(0).getCellrangebyname("link")
oLink = oCell.textfields.getbyindex(0)
' invalid argument: oView.select(oLink)
oView.select(oCell)
dispatch_InputMode
wait 2000
' when you have selected the field within the 2 seconds, the hyperlink gets openened
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
oDisp.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:OpenHyperlinkOnCursor", "", 0, Array())
End Sub
Sub dispatch_InputMode()
Dim dispatcher,frame
frame = thisComponent.getCurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(frame, ".uno:SetInputMode", "", 0, Array())
end sub
|
_________________ Rest in peace, oooforum.org
Get help on http://forum.openoffice.org |
|
| Back to top |
|
 |
rebelxt OOo Enthusiast


Joined: 10 Dec 2006 Posts: 114 Location: StLouis
|
Posted: Sun Mar 04, 2007 10:12 am Post subject: |
|
|
Thanks, I think....
Have to look at this to see if it does me any good in this situation. |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Sun Mar 04, 2007 10:28 am Post subject: |
|
|
I think I've got it.
| Code: |
Sub Main
oCell = thisComponent.sheets(0).getCellrangebyname("link")
oLink = oCell.textfields.getbyindex(0)
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
oDisp.executeDispatch(ThisComponent.CurrentController.Frame, oLink.URL, "", 0, Array())
End Sub
|
Currently my office does not know how to call a browser by http-URLs and I don't know how to fix it. So I have tested this with a macro-url in a cell: "vnd.sun.star.script:Standard.Module1.message?location=document&language=Basic"
The other macro simply shows a message box when I call the above Sub Main. _________________ Rest in peace, oooforum.org
Get help on http://forum.openoffice.org |
|
| Back to top |
|
 |
rebelxt OOo Enthusiast


Joined: 10 Dec 2006 Posts: 114 Location: StLouis
|
Posted: Sun Mar 04, 2007 4:54 pm Post subject: |
|
|
| If http-URLs are a consideration, my links are to .gif and .pdf files. Does that make a difference? |
|
| Back to top |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Sun Mar 04, 2007 4:56 pm Post subject: |
|
|
Congratulations, Villeroy.
That code has an unexpected result on my system. My link is Google and the script opens Google as an html page in Writer. The same link, when used in the GUI, opens Google in the web browser. _________________ search forum by month |
|
| Back to top |
|
 |
|