How to open an external webpage using Base

Hi everyone.
I ran into another challenge (problem).

I have the need to open an external “www” URL. I have a push button on "MainForm " and I need to open a help page on a website of mine that I am in the progress of building.

On In base how to open a URL field? shows how to open, I assume, an embedded document or page. I need to go out to the web. I tried replacing “txtURL” with the webpage URL and the “Push Button 1” with “btnHelp” I’m sure this line must be revised to reflect an external URL "oField = oForm.getByName(“txtURL”) "

Here is my particulars and the script by Ratslinger from the page above.

Button: btnHelp
URL: https://whitehousecomms-arc.org/

Sub GetURL
oForm = ThisComponent.Drawpage.Forms.getByName(“MainForm”)
DocCtl = ThisComponent.getCurrentController()
oField = oForm.getByName(“txtURL”)
oButton = oForm.getByName(“Push Button 1”)
CtlView = DocCtl.GetControl(oField)
oButton.TargetUrl = CtlView.Text
end sub

EXTRA NOTE: The even better event to execute the macro would be the “get focus” of the push_button itself
This executes the macro only when actually needed (and reads always the actual displayed content of the text field)

Thanks very much! Inquiring minds want to know.

I have the need to open an external “www” URL. I have a push button on "MainForm " and I need to open a help page on a website of mine that I am in the progress of building.

Just to open a help page you don’t need a macro, see the image bellow, specially Action… and URL… fields.

1 Like

I am trying it out. Thanks


I am doing something dumb somewhere I can’t get it to work.

I am adding another screenshot of the entire properties window and the Push Button. I don’t know if it matters but my properties form is much different than yours.

Not really: both shows a URL field directly below the row “Action”. But you’ve choosen the help-url field for your URL instead… Maybe try the same field used by @Gbp

Got it, thanks! I thought I tried this field last night and go an error. It is working now and that is all that matters! I appreciate your help. I have a couple other issues I am working on but I’ll dig into it some more before I create another subject thread.

1 Like

My answer on the page you reference is how you get at it. You’ll need to plug in your URL in the appropriate place. And you’ll need to hook up the button click event to run this macro code. Let me know if you don’t know how to do that.

    '-Create the needed SystemShellExecute service object'
    DIM oShell AS OBJECT :oShell=createUnoService("com.sun.star.system.SystemShellExecute")
    	
    '-Get the URL from the current field'
    DIM s AS STRING      :s     =oEvent.Source.Model.CurrentValue : s = convertToUrl(s)

    '-Open the URL in your browser'
    oShell.execute(s,,0)

I am researching what you are doing in this script. I can’t figure out where you are referring to here. [quote=“EasyTrieve, post:2, topic:104173”]
You’ll need to plug in your URL in the appropriate place
[/quote]

Thank you!

When you press/click the button this generates an event. You select the Events tab to define the code which runs when an event occurs. So first you create the macro and give it a location and a name. Then you point the Event to it. Since you have a fixed URL you can simply use a literal string for it.

I haven’t updated this in awhile, but this is a good place to look for documentation and tutorials.

In particular look at the section titled:

INDEPENDENT DOCUMENTATION

Andrew Pitonyak

1 Like

Thank you very much.