Macro to Update Links in Spreadsheet

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
AJB-work
Posts: 53
Joined: Wed Sep 17, 2008 4:07 pm
Location: Akron, Ohio, USA

Macro to Update Links in Spreadsheet

Post by AJB-work »

I have recently migrated our office from MS Office to OpenOffice. I have received complaints that when you had a spreadsheet that referenced cells in another spreadsheet it would update automatically while working in both spreadsheets.

Example:
Cell A1 in File A is referenced in File B. If both files are open and the contents of Cell A1 in File A was edited the new contents would appear in File B. This would happen without having to Save File A or the operator having to manually tell File B to update. It was also done with the DDE link method, just a simple formula.

Now in Calc File A needs to be saved after editing cell A1. Then in File B you have to go to Edit, Links, Update, Close. I tried to record a macro to handle the steps in File B. I figure if I can give a toolbar icon for my users to click to handle the update in File B they will accept that File A needs saved and these extra steps better than going through all of th steps mentioned.

My problem is that the recorded macro does handle the Edit>Links part but it stops there. It will not do the Update and the Close of the dialog. I am totally new to macros and have only scratched the surface. Can those of you in the know offer me any advice in automating this process??

Here is the code for the macro I tried to create:

Code: Select all

REM  *****  BASIC  *****

Sub Main

End Sub


sub UpdateLinks
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:EditLinks", "", 0, Array())


end sub
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to Update Links in Spreadsheet

Post by Villeroy »

My [Tutorial] External Links In Calc provides infos regarding all 5 methods including links to required interfaces.
See also "refreshAllSheetLinks" in http://user.services.openoffice.org/en/ ... =20&t=6004
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
AJB-work
Posts: 53
Joined: Wed Sep 17, 2008 4:07 pm
Location: Akron, Ohio, USA

Re: Macro to Update Links in Spreadsheet

Post by AJB-work »

I read through that.

My problems are our accounting users have a slew of spreadsheets that already exist that they are using. I don't want to make them recreate the links and frankly they shouldn't have to. Unfortunately this is one of those items that just happens to work better in Excel. If I can provide them with a toolbar icon that will handle all of the steps to update the links in the target file I will make them much happier than they are right now.

I just can't get the macro to handle the buttons in the dialog. Please help me with the macro. I appreciate the alternate methods but my current situation forces me to play the cards I am currently dealt so to speak.
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to Update Links in Spreadsheet

Post by Villeroy »

:x
What is this going to be? A programming tutorial? Do you want me to do your work? Just run the code I linked.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
AJB-work
Posts: 53
Joined: Wed Sep 17, 2008 4:07 pm
Location: Akron, Ohio, USA

Re: Macro to Update Links in Spreadsheet

Post by AJB-work »

Villeroy wrote::x
What is this going to be? A programming tutorial? Do you want me to do your work? Just run the code I linked.
Ouch. Sorry.

I didn't see the link to the other topic underneath the tutorial when I replied. I thought you were just directing me to alternate approaches and not macro code. I took another look at your first response after seeing your last reply.

The refresh all links code worked great thank you. No tutorial needed and it kinda looks like you did the work already. I wasn't expecting to get code but maybe a tip on how to tweak what I already did. Thanks again, I replaced my code with yours and made a toolbar icon for it. Showed it to the user in need and he said that will really help him and his users that are missing Excel.

Thanks again Villeroy!
OOo 3.0.X on Ms Windows XP
Post Reply