[Solved] Convert IP addresses into hyperlinks

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
Synthex
Posts: 10
Joined: Tue Feb 25, 2014 9:14 pm

[Solved] Convert IP addresses into hyperlinks

Post by Synthex »

I have OpenOffice spreadsheet with a column of IP addresses, in column A (without a leading "http://")
How can I turn them all into hyperlinks automatically? I tried the following macro,

Code: Select all

Sub ConvertToHyperlinks()
  Dim Cell As Variant
  For Each Cell In Selection
    Cell.Hyperlinks.Add Cell, "http://" & Cell.Text
  Next
End Sub
but it produces error "Basic runtime error. Object variable not set."
Last edited by Synthex on Wed Feb 26, 2014 3:31 pm, edited 1 time in total.
Version: 7.0.4.2 on Linux Debian
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Convert IP addresses into hyperlinks

Post by acknak »

Hello, welcome to the community forum!

I prefer to keep such items as pure data and use HYPERLINK; no macro needed: =HYPERLINK("http://"&IP_Cell;"Click")

If you really want to convert the IP addresses into clickable links, first use Edit > Find & Replace to add the "http://".

Then select all the IPs, press F2 to edit and type a space. The current cell should change to a link at this point. Now (first delete the extra space) press Alt+Shift+Enter and all the selected items should change as well.
AOO4/LO5 • Linux • Fedora 23
Synthex
Posts: 10
Joined: Tue Feb 25, 2014 9:14 pm

Re: Convert IP addresses into hyperlinks

Post by Synthex »

Hello, thank you for input.
I'm not sure how to use this formula: I used similar formula: =HYPERLINK("http://" & A1,A1), and copy down, but it require additional column B1 where hyperlinks will be created. (I wanted to avoid extra column)

The 2nd method - when I come to the last step (press Alt+Shift+Enter), it creates all IPs the same, just copies the first IP address, strange.
Version: 7.0.4.2 on Linux Debian
Synthex
Posts: 10
Joined: Tue Feb 25, 2014 9:14 pm

Re: Convert IP addresses into hyperlinks

Post by Synthex »

I find this advice works good for me (last post by MrProgrammer):
viewtopic.php?f=9&p=269162
Version: 7.0.4.2 on Linux Debian
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Convert IP addresses into hyperlinks

Post by acknak »

Synthex wrote:... just copies the first IP address, strange.
Ouch. Yep. My bad. I was testing it with all the same IP and I forgot that that's the point of that shortcut: copy one cell into all the selected cells.

So, you may need a macro after all, if you can't work with the extra column.
AOO4/LO5 • Linux • Fedora 23
User avatar
RoryOF
Moderator
Posts: 35269
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Convert IP addresses into hyperlinks

Post by RoryOF »

Why not put in the extra column, then Hide it?
Apache OpenOffice 4.1.17 on Xubuntu 26.04.1 LTS
User avatar
MrProgrammer
Moderator
Posts: 5481
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Convert IP addresses into hyperlinks

Post by MrProgrammer »

Hi, and welcome to the forum.

[Tutorial] Text to Columns, Q35/A35.

If this answered your question please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Synthex
Posts: 10
Joined: Tue Feb 25, 2014 9:14 pm

Re: Convert IP addresses into hyperlinks

Post by Synthex »

RoryOF wrote:Why not put in the extra column, then Hide it?
I know, there's nothing wrong with the method, I'd just preffer to keep spreadsheet data small as possible.
Version: 7.0.4.2 on Linux Debian
Synthex
Posts: 10
Joined: Tue Feb 25, 2014 9:14 pm

Re: Convert IP addresses into hyperlinks

Post by Synthex »

MrProgrammer wrote:Hi, and welcome to the forum.

[Tutorial] Text to Columns, Q35/A35.
Hi, I tried Q35/A35 from Tutorial too, but got only one IP in the last row hyperlinked.(cell, that was active when rows was selected). The data in the other rows not hyperlinked and leading "http://" is missing too.
Version: 7.0.4.2 on Linux Debian
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Convert IP addresses into hyperlinks

Post by B Marcelly »

Hi,
Here is a basic method to run through all cells of a range.

Code: Select all

Dim sh As Object, z As Object, c As Object
Dim qCells As Object, enuCells As Object

sh = ThisComponent.Sheets.getByName("YourSheetName")
z = sh.getCellRangeByName("B2:B5") ' your column (or rectangle)
qCells = z.queryContentCells(-1)
enuCells = qCells.Cells.createEnumeration
Do While enuCells.hasMoreElements
  c = enuCells.nextElement
  c.Formula = "=HYPERLINK(""http://" & c.String & """)"
Loop
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
Synthex
Posts: 10
Joined: Tue Feb 25, 2014 9:14 pm

Re: Convert IP addresses into hyperlinks

Post by Synthex »

Thank you, works fine.
Version: 7.0.4.2 on Linux Debian
User avatar
MrProgrammer
Moderator
Posts: 5481
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: [Solved] Convert IP addresses into hyperlinks

Post by MrProgrammer »

Synthex wrote:I tried Q35/A35 from Tutorial too, but got only one IP in the last row hyperlinked.(cell, that was active when rows was selected)
I know this topics is marked Solved, but I'm pretty sure the procedure in A35 works. I tested it before putting it in the tutorial and I retested again today. The procedure works on my system (OOo 3.2 on Mac OS level 10.6.8). I suspect the problem could be that you didn't follow the instructions.
• Select the column with the web email addresses then: Format > Cells > Numbers > Format Code > "=HYPERLINK("\""http://"@\"")"
• Select the column with the web email addresses then: Data > Text to Columns > OK
• Select the column with the web email addresses then: Format > Default Formatting
• Select the column with the web email addresses then: Data > Text to Columns > OK
You should select the column four times as indicated by clicking the column header, for example, the A above cell A1. If you don't do that, Text to Columns may not understand that it should process all the cells. For the procedure to work, the dialog's preview must show all the rows. If it's only showing the last row, this is the cause of your difficulty.

After the first step, if the first row has a column label which you don't want to hyperlink you can remove the formatting by using Format > Default Formatting on the cell before proceeding to step 2.
 Edit: The lines above should say "column with the web addresses" instead of "column with the email addresses" 
Last edited by MrProgrammer on Thu Feb 27, 2014 4:32 pm, edited 2 times in total.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Synthex
Posts: 10
Joined: Tue Feb 25, 2014 9:14 pm

Re: [Solved] Convert IP addresses into hyperlinks

Post by Synthex »

I retested tip A35 from Tutorial and yes, it works properly.
The problem was because I selected the column only once, since it remained active(selected) all time, until the end of the procedure.
I had to deselect column first, then select it again, all four times. Btw, why it named column with the email addresses, what relation?
Version: 7.0.4.2 on Linux Debian
Locked