OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Following a hyperlink

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
rebelxt
OOo Enthusiast
OOo Enthusiast


Joined: 10 Dec 2006
Posts: 114
Location: StLouis

PostPosted: Sat Mar 03, 2007 9:06 am    Post subject: Following a hyperlink Reply with quote

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
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Sat Mar 03, 2007 4:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
rebelxt
OOo Enthusiast
OOo Enthusiast


Joined: 10 Dec 2006
Posts: 114
Location: StLouis

PostPosted: Sat Mar 03, 2007 7:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Sun Mar 04, 2007 9:47 am    Post subject: Reply with quote

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 https://forum.openoffice.org
Back to top
View user's profile Send private message
rebelxt
OOo Enthusiast
OOo Enthusiast


Joined: 10 Dec 2006
Posts: 114
Location: StLouis

PostPosted: Sun Mar 04, 2007 10:12 am    Post subject: Reply with quote

Thanks, I think.... Rolling Eyes

Have to look at this to see if it does me any good in this situation.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Sun Mar 04, 2007 10:28 am    Post subject: Reply with quote

Laughing 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 https://forum.openoffice.org
Back to top
View user's profile Send private message
rebelxt
OOo Enthusiast
OOo Enthusiast


Joined: 10 Dec 2006
Posts: 114
Location: StLouis

PostPosted: Sun Mar 04, 2007 4:54 pm    Post subject: Reply with quote

If http-URLs are a consideration, my links are to .gif and .pdf files. Does that make a difference?
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Sun Mar 04, 2007 4:56 pm    Post subject: Reply with quote

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. Sad The same link, when used in the GUI, opens Google in the web browser.
_________________
search forum by month
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group