Ask Your Question
0

Help - macro to update external links

asked 2017-08-01 20:34:40 +0100

staylorx gravatar image

I tried 'record macro' but the section I wanted to capture was remarked out with little to no detail.

I'm looking to create a macro where I can update a link and run through the selection wizard [or bypass and update/refresh directly]

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-08-03 07:17:51 +0100

staylorx gravatar image

This is what I came up with - goes through each sheet, copying the concatenated URL and uses it to import the External data. 16 tabs takes about 7 min to complete, much faster and WAY less keystrokes than doing each sheet manually.

sub tabSwitch

dim document   as object
dim dispatcher as object
dim oAddress as Object
dim sheet as Object
dim oSheets as Object
dim n as Long

document   = ThisComponent
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oSheets = ThisComponent.Sheets

' count number of sheets and set pointer for last one - allows for growth
NumSheets = (oSheets.Count - 1)

' loop through each sheet
For n = 1 to NumSheets
    ' set active sheet
    sheet = document.Sheets(n)
    ' set cell to insert Link External Data
    oAddress = sheet.getCellByPosition( 4, 33 ).getCellAddress()
    ' insert at (cell, url, what HTML, default, default) defaults were what the sample had and I didn't change them
    document.AreaLinks.insertAtPosition( oAddress, sheet.getCellByPosition(3, 33).String, "HTML_tables", "calc_HTML_WebQuery", "0 0" )
Next n

end sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-08-01 20:34:40 +0100

Seen: 305 times

Last updated: Aug 03 '17