[Solved] LoadcomponentfromURL fails to open the document

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Muthuvel
Posts: 12
Joined: Sat Jun 20, 2020 7:42 pm

[Solved] LoadcomponentfromURL fails to open the document

Post by Muthuvel »

I am totally new to open office programming. I am trying to open a writer document and save it in a different name using a macro written in BASIC.

I get the error " BASIC runtime error. Object variable not set" in the following line

Code: Select all

Doc.storeAsURL(Url, FileProperties()) 
What is wrong in this code?
Full code snippet is given below

Code: Select all

sub SaveAsTest
Dim Doc 
Dim Dummy() 
Dim Url As String
Dim SearchFlags As Long
 
SearchFlags = com.sun.star.frame.FrameSearchFlag.CREATE + _
              com.sun.star.frame.FrameSearchFlag.ALL
Url = "file:///C:/temp/test.odt"
Doc = StarDesktop.loadComponentFromURL(Url, "MyFrame", SearchFlags, Dummy)
Dim FileProperties(0) As New com.sun.star.beans.PropertyValue

' ... Initialize Doc 
 
Url = "file:///c:/temp/test3.odt"
FileProperties(0).Name = "Overwrite"
FileProperties(0).Value = True
Doc.storeAsURL(Url, FileProperties()) 
end sub

Last edited by robleyd on Sun Jun 21, 2020 8:20 am, edited 3 times in total.
Reason: Add green tick
OpenOffice 4.1 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: StoreURLAs error object variable not set

Post by Zizi64 »

Please upload the whole code list of the Sub.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: StoreURLAs error object variable not set

Post by JeJe »

Works for me, I don't get an error.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Muthuvel
Posts: 12
Joined: Sat Jun 20, 2020 7:42 pm

Re: StoreURLAs error object variable not set

Post by Muthuvel »

@JeJe
I wonder. The difference between you and me is the operating system only. Could my operating system (Windows 10) be the reason?
OpenOffice 4.1 on Windows 10
Muthuvel
Posts: 12
Joined: Sat Jun 20, 2020 7:42 pm

Re: StoreURLAs error object variable not set

Post by Muthuvel »

@ZiZi64
Thank you for your effort to solve it.
The full list is already given in my question. I once again give below. That's all my code.

Code: Select all

sub SaveAsTest
Dim Doc 
Dim Dummy() 
Dim Url As String
Dim SearchFlags As Long
 
SearchFlags = com.sun.star.frame.FrameSearchFlag.CREATE + _
              com.sun.star.frame.FrameSearchFlag.ALL
Url = "file:///C:/temp/test.odt"
Doc = StarDesktop.loadComponentFromURL(Url, "MyFrame", SearchFlags, Dummy)
Dim FileProperties(0) As New com.sun.star.beans.PropertyValue

' ... Initialize Doc 
 
Url = "file:///c:/temp/test3.odt"
FileProperties(0).Name = "Overwrite"
FileProperties(0).Value = True
Doc.storeAsURL(Url, FileProperties()) 
end sub

OpenOffice 4.1 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: StoreURLAs error object variable not set

Post by Zizi64 »

Sorry, I believed that the line

Code: Select all

' ... Initialize Doc  
means some other commands.

I just tried your code in my AOO 4.1.5 and AOO 4.1.7 portable versions on my Windows10x64Prof. operating system, and it worked fine.

Other environment parameters:
The macro code is located in the MyMacros - Standard library - Module1 of the AOO, but not in an .odt document file.
I launched the macro by a button click from a third Writer document.
And the 'temp' directory is a User-created folder on my C drive, and I have (the code has) has full write rights.

What about your environment parameters?

And what a subversion of the Apache OpenOffice are you using now?
AOO 4.1.x? (Do you using same version as JeJe: AOO 4.1.2 ?)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Muthuvel
Posts: 12
Joined: Sat Jun 20, 2020 7:42 pm

Re: StoreURLAs error object variable not set

Post by Muthuvel »

@JeJe and @ZiZi64
Thank you for trying in your systems and informing me that it is working.
Otherwise i would have misled my self in a wrong direction. I found the problem. The file is password protected. The loadDocumentFromURL method has failed to open the file without supplying a password and the Doc object is not at all initialised. It is null. That is why i got the error " Object variable not set".

Initially i had passed a "Dummy" array in the line

Code: Select all

Doc = StarDesktop.loadComponentFromURL(Url, "MyFrame", SearchFlags, Dummy)
Now I have suppied the password with the FileProp array as follows

Code: Select all

FileProp(0).Name = "Password"
  FileProp(0).Value = "tmb"
Doc = StarDesktop.loadComponentFromURL(Url, "MyFrame", SearchFlags, FileProp())
Now the file is opened and saved in a different name. Your support is appreciated
OpenOffice 4.1 on Windows 10
Post Reply