Hello @Albert1976,
First apologies for thinking that was you on AOO forum. The similarity was striking.
The code is simple but requires specific planning on your part. Start with the links themselves. The links you have should not have an automatic update set (Update every x seconds) if you are to update by a button. HTML table links are all grouped under AreaLinks
and the destination sheet can be identified in DestArea.Sheet
. When the appropriate link is found, the refresh()
method can be applied.
Have tested this and is working using just one macro for all sheets. You will have one button for each sheet and each button will point to the same macro using the Execute action
event. A key point here is naming the control. The macro will use this name to determine which links to update. In my test and in this macro the two buttons were internally named Sheet1
and Sheet2
.
Here is the macro:
Option Explicit
Sub UpdateTables(oEvent)
Dim sSheet As String
Dim iSheet As Integer
Dim iLinkCount As Integer
Dim x As Integer
Dim oLink As Object
Rem Get the name of the button pushed
sSheet = oEvent.Source.Model.Name
Rem Set the variable to the relative sheet number depending upon the name
Rem Sheets are numbered starting from zero
If sSheet = "Sheet1" Then
iSheet = 1 Rem This is second sheet
ElseIf sSheet = "Sheet2" Then
iSheet = 2 Rem This is third sheet
EndIF
Rem Obtain total number of links in the document
iLinkCount = ThisComponent.AreaLinks.getCount()
Rem Cycle through links looking for those on a specific sheet
For x = iLinkCount to 1 Step -1
oLink = ThisComponent.AreaLinks.getByIndex(x-1)
Rem When link on specific sheet is found, refresh the link
If oLink.DestArea.Sheet = iSheet Then
oLink.refresh()
End If
Next x
End Sub
Of course you will need to modify the code (If statement checking for button names) and add additional buttons for the number of sheets you have in your document.