| View previous topic :: View next topic |
| Author |
Message |
Paco General User


Joined: 18 Sep 2005 Posts: 26 Location: Valcourt, Québec, Canada
|
Posted: Sun Sep 25, 2005 3:04 pm Post subject: A macro to update links then close the dialog box... |
|
|
Hi all!
I'm currently learning how to use Macros; I have this one...
########################################################
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
########################################################
...that I would like to make it go further. I've created a button that when pressed, run this macro and I want it to
/Edit/Links...//Update//then CLose
but it's currently stoping at the Links dialog box... Once Update, I would like the macros to Close the dialog box so I can go on with my input in this sheet.
Now, is something missing from the macro above to have it to Update the links and to Close the dialog box?
Thanks in advance for any help! _________________ Ooo - Love it! Thanks Ooo team! Using v2 on Win
--------------------------------------------------------------
USINUM - Paco's area |
|
| Back to top |
|
 |
Zarius OOo Enthusiast


Joined: 21 Jan 2005 Posts: 142 Location: Brisbane, Australia
|
Posted: Wed Sep 28, 2005 3:38 am Post subject: |
|
|
Hi,
After a little poking around I found this:
| Code: | | ThisComponent.updateLinks |
Does this do what you wanted?
Regards,
Zarius. _________________ Zarius Tularial. (WinXP - OOo 1.1.4, FedoraCore 4 - OOo 2.0, RHEL4 - StarOffice 7)
Quoots - a quicker way to open your documents and fill in template details in OOo. (written in OOBasic) |
|
| Back to top |
|
 |
Paco General User


Joined: 18 Sep 2005 Posts: 26 Location: Valcourt, Québec, Canada
|
Posted: Wed Sep 28, 2005 4:39 am Post subject: |
|
|
Should I just paste it on a new line inside my current macro?... I'll try it soon and let you know...
Thanks! _________________ Ooo - Love it! Thanks Ooo team! Using v2 on Win
--------------------------------------------------------------
USINUM - Paco's area |
|
| Back to top |
|
 |
Zarius OOo Enthusiast


Joined: 21 Jan 2005 Posts: 142 Location: Brisbane, Australia
|
Posted: Wed Sep 28, 2005 4:57 am Post subject: |
|
|
You should be able to replace your entire macro with it - if all you want the macro to do is update the links on the current document, without any dialog box at all. That one line does it for you.
| Code: |
sub updateLinks
ThisComponent.updateLinks()
end sub |
Then just customise your toolbar and add the macro there, or bind it to a keyboard shortcut.
Although there is already an option for it when you customise shortcuts or the toolbar: under Edit/Update All Links. "ThisComponent.updateLinks" could be handy if you wanted to do other stuff in your macro first and then update the links (or update links & then do stuff). _________________ Zarius Tularial. (WinXP - OOo 1.1.4, FedoraCore 4 - OOo 2.0, RHEL4 - StarOffice 7)
Quoots - a quicker way to open your documents and fill in template details in OOo. (written in OOBasic)
Last edited by Zarius on Wed Sep 28, 2005 6:40 am; edited 1 time in total |
|
| Back to top |
|
 |
Paco General User


Joined: 18 Sep 2005 Posts: 26 Location: Valcourt, Québec, Canada
|
Posted: Wed Sep 28, 2005 5:37 am Post subject: |
|
|
Thanks a-l-o-t!
Curious: where did you find the info? _________________ Ooo - Love it! Thanks Ooo team! Using v2 on Win
--------------------------------------------------------------
USINUM - Paco's area |
|
| Back to top |
|
 |
Zarius OOo Enthusiast


Joined: 21 Jan 2005 Posts: 142 Location: Brisbane, Australia
|
Posted: Wed Sep 28, 2005 6:39 am Post subject: |
|
|
No worries.
As for finding the info: well, the easier bit is the keyboard shortcuts, just gotta run through the various things you can set in there a few times so you can remember them later when you try to do something (hopefully before doing it the hard way... done that a few times .
For the code, "ThisComponent" usually returns the current document you're in, and I knew updating the links was either going to be a responability of the document or each individual "section", so I inspected ThisComponent with a short macro I found elsewhere - however I'd recommend the Xray tool over at OOoMacros - it'll let you look at what properties objects have, as well as what you can run with them (methods - such as updateLinks()). _________________ Zarius Tularial. (WinXP - OOo 1.1.4, FedoraCore 4 - OOo 2.0, RHEL4 - StarOffice 7)
Quoots - a quicker way to open your documents and fill in template details in OOo. (written in OOBasic) |
|
| Back to top |
|
 |
baba General User

Joined: 21 Oct 2006 Posts: 41
|
Posted: Sun Dec 03, 2006 7:34 pm Post subject: |
|
|
[quote="Zarius"]You should be able to replace your entire macro with it - if all you want the macro to do is update the links on the current document, without any dialog box at all. That one line does it for you.
| Code: |
sub updateLinks
ThisComponent.updateLinks()
end sub |
[/quote
I found you post when searching for the same problem, updating links via a macro. However, ThisCompponent.UpdateLinks() generates an error message at runtime, method not supported. I am using OO.o 2.0. I wonder if this is changed in this release?] |
|
| Back to top |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Mon Dec 04, 2006 4:46 am Post subject: |
|
|
I have version 2.0.2 and the method seems to be unavailable for any object I can find. There is a method for updating links using the dispatcher on loading a document. See here for constants.
| Code: | Sub updateLinksOnLoad
Dim aProps( 0 ) as new com.sun.star.beans.PropertyValue, sUrl as String, oDoc as Object
sUrl = "file:///<etc>"
If NOT FileExists( sUrl ) Then : Msgbox( "No file named " & sUrl ) : Exit sub : End If
aProps( 0 ).name = "UpdateDocMode"
aProps( 0 ).value = 3 'full update
oDoc = StarDesktop.loadComponentFromURL( sUrl, "_blank", 0, aProps() )
End Sub |
_________________ search forum by month |
|
| Back to top |
|
 |
baba General User

Joined: 21 Oct 2006 Posts: 41
|
Posted: Mon Dec 04, 2006 6:40 am Post subject: |
|
|
| noranthon wrote: | I have version 2.0.2 and the method seems to be unavailable for any object I can find. There is a method for updating links using the dispatcher on loading a document. See here for constants.
| Code: | Sub updateLinksOnLoad
Dim aProps( 0 ) as new com.sun.star.beans.PropertyValue, sUrl as String, oDoc as Object
sUrl = "file:///<etc>"
If NOT FileExists( sUrl ) Then : Msgbox( "No file named " & sUrl ) : Exit sub : End If
aProps( 0 ).name = "UpdateDocMode"
aProps( 0 ).value = 3 'full update
oDoc = StarDesktop.loadComponentFromURL( sUrl, "_blank", 0, aProps() )
End Sub |
|
I need to update links after sheets are loaded.The toolbar sequence is Edit-Links-(select a link)-Update-Close. Is that possible? |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Mon Dec 04, 2006 11:37 am Post subject: |
|
|
| Quote: | | I need to update links after sheets are loaded.The toolbar sequence is Edit-Links-(select a link)-Update-Close. Is that possible? |
@Baba,
I think you just need to set Tools>Options>Calc>General>"Update links on open" to "Always".
@Zarius and others,
No, thisComponent.updateLinks does not apply to a spreadsheet.
thisComponent.getLinks might be misleading because it returnes a name-container with 3 other name-containers for sheets, named refs, and database-ranges.
But a service SpreadsheetDocument has three properties:
1. DDE-links created through formula DDE(service;path;bookmark)
2. AreaLinks created through Insert>Link to External Data...
I have to admit I was not aware of this menu-item. I ignored it for years, just like that "Hyperlink Bar". In general I avoid linked sheets like the pest.I keep one experimental oooforum_ext.ods for supporting this forum.
3a. SheetLinks created through Insert>Sheet from file..., getLinkMode() = com.sun.star.sheet.SheetLinkMode.NORMAL
3b. SheetLinks created through references like ='file:///path/doc.ods'#SheetName.A1, oLink.getLinkMode() = com.sun.star.sheet.SheetLinkMode.VALUE
This is the code of my experimental oooforum_ext.ods. It requires the Xray tool to be installed:
| Code: |
REM ***** BASIC *****
sub xray_ThisComponentLinks
oLinkContainer = thisComponent.getLinks
aCategories = oLinkContainer.getElementNames()
for i = 0 to uBound(aCategories())
sCategory = aCategories(i)
oLinks = oLinkContainer.getByName(sCategory).getLinks
aNames() = oLinks.getElementNames()
print "Category: ", sCategory ,"Count: ",uBound(aNames()) +1
for j = 0 to uBound(aNames())
myxray oLinks.getByName(aNames(j))
if msgbox("More?",1)=2 then exit for
next
next
End Sub
Sub xray_AreaLinks
oEnum = thisComponent.AreaLinks.createEnumeration
while oEnum.hasMoreElements
oLink = oEnum.NextElement
myxray oLink
wend
end sub
Sub xray_SheetLinks
oEnum = thisComponent.SheetLinks.createEnumeration
while oEnum.hasMoreElements
oLink = oEnum.NextElement
myxray oLink
wend
end sub
Sub xray_DDELinks
oEnum = thisComponent.DDELinks.createEnumeration
while oEnum.hasMoreElements
oLink = oEnum.NextElement
myxray oLink
wend
end sub
|
This is my xray-wrapper, called by the above methods:
| Code: |
Sub myXRay(v)
Dim i%,obj,x%,sRec$
Static iRec%
globalscope.basiclibraries.loadlibrary("XrayTool")
if isarray(v) then
iRec = iRec +1
for i = lBound(v) to uBound(v)
obj = v(i)
myXRay obj 'recursive for nested arrays
if (i< uBound(v)) then
If iRec > 1 then sRec$ = "[Recursion="& iRec &"] " : else sRec =""
x = msgbox(sRec & i -lBound(v)+2 &" / "& uBound(v) - lBound(v) +1,5,"X-ARRAY")
if x = 2 then exit for
endif
next
iRec = iRec -1
else
xray v
end if
End Sub
|
So we have 4 methods for importing data into a spreadsheet (1,2,3a and 3b above),
5. import of datasource-objects into database-ranges
6. import of datasource-objects into data pilots
EDIT:
Forgot to add a macro answering the original post:
| Code: |
Sub refreshAllSheetLinks()
oEnum = thisComponent.AreaLinks.createEnumeration
while oEnum.hasMoreElements
oLink = oEnum.NextElement
oLink.refresh
wend
oEnum = thisComponent.SheetLinks.createEnumeration
while oEnum.hasMoreElements
oLink = oEnum.NextElement
oLink.refresh
wend
oEnum = thisComponent.DDELinks.createEnumeration
while oEnum.hasMoreElements
oLink = oEnum.NextElement
oLink.refresh
wend
End Sub
|
_________________ Rest in peace, oooforum.org
Get help on http://forum.openoffice.org |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|