Hi
I need to access two worksheets in one macro. I need to transfer some data from file2.ods to current file (file1.ods).
Both of them are open and are in same directory.
document1 = ThisComponent
Sheets1 = document1.Sheets
Sheet1 = Sheets1.getByName("Destination")
"How to Define document2 ???"
Sheets2 = document2.Sheets
Sheet2 = Sheets2.getByName("Source")
[Solved] Accessing to a file other that ThisComponent
[Solved] Accessing to a file other that ThisComponent
Last edited by Hagar Delest on Wed Feb 22, 2017 5:26 pm, edited 2 times in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice 4, Windows 10
Re: Accessing to a file other that ThisComponent
You can get a reference to the document by loading it like this
Code: Select all
FileURL = convertToURL("c:\users\fjcc\desktop\FILE2.ods"
oDoc2 = StarDesktop.loadComponentFromURL(FileURL, "_blank", 0, Array())
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Accessing to a file other that ThisComponent
Thank You. The solution you mentioned kind of worked, but the problem is every time I run the Marco, it opens the "file2.ods" in a new window; even if the file is already open! Is there a solution that recognize "open" files and don't re-open it?
OpenOffice 4, Windows 10
Re: Accessing to a file other that ThisComponent
You can iterate over the open files and select the one you want. If you don't find it, you can load it. That would look something like
Code: Select all
Flag = 0
FileURL = convertToURL("c:\users\fjcc\desktop\FILE2.ods"
Components = StarDesktop.getComponents()
CompEnum = Components.createEnumeration
While CompEnum.hasMoreElements
OneComp = CompEnum.nextElement
If OneComp.URL = FileURL Then
oDoc2 = OneComp
Flag = 1
End If
Wend
If Flag = 0 Then
oDoc2 = StarDesktop.loadComponentFromURL(FileURL, "_blank", 0, Array())
End If
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Accessing to a file other that ThisComponent
I debuged the program and it seems it detects the open file and the flag becomes 1, however the file and sheets are not accessible:
MySheet = oDoc2.Sheets.GetByName("Sheet1")
The mentioned command was accessible when I opened the file by:
oDoc2 = StarDesktop.loadComponentFromURL(FileURL, "_blank", 0, Array())
MySheet = oDoc2.Sheets.GetByName("Sheet1")
The mentioned command was accessible when I opened the file by:
oDoc2 = StarDesktop.loadComponentFromURL(FileURL, "_blank", 0, Array())
OpenOffice 4, Windows 10
Re: Accessing to a file other that ThisComponent
My Mistake.
The code worked perfect. Thank you.
The code worked perfect. Thank you.
OpenOffice 4, Windows 10
Re: [Solved] Accessing to a file other that ThisComponent
You could also replace the frame descriptor "_blank" (new frame) with "_default".
See http://www.openoffice.org/api/docs/comm ... entFromURL
See http://www.openoffice.org/api/docs/comm ... entFromURL
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice