[Solved] LoadcomponentfromURL fails to open the document

Creating a macro - Writing a Script - Using the API

[Solved] LoadcomponentfromURL fails to open the document

Postby Muthuvel » Sat Jun 20, 2020 8:09 pm

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   Expand viewCollapse view
Doc.storeAsURL(Url, FileProperties())

What is wrong in this code?
Full code snippet is given below
Code: Select all   Expand viewCollapse view
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
Muthuvel
 
Posts: 12
Joined: Sat Jun 20, 2020 7:42 pm

Re: StoreURLAs error object variable not set

Postby Zizi64 » Sat Jun 20, 2020 10:41 pm

Please upload the whole code list of the Sub.
Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
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.
User avatar
Zizi64
Volunteer
 
Posts: 9429
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: StoreURLAs error object variable not set

Postby JeJe » Sun Jun 21, 2020 12:26 am

Works for me, I don't get an error.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 1088
Joined: Wed Mar 09, 2016 2:40 pm

Re: StoreURLAs error object variable not set

Postby Muthuvel » Sun Jun 21, 2020 5:07 am

@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

Postby Muthuvel » Sun Jun 21, 2020 5:09 am

@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   Expand viewCollapse view
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
Muthuvel
 
Posts: 12
Joined: Sat Jun 20, 2020 7:42 pm

Re: StoreURLAs error object variable not set

Postby Zizi64 » Sun Jun 21, 2020 6:58 am

Sorry, I believed that the line
Code: Select all   Expand viewCollapse view
' ... 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; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
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.
User avatar
Zizi64
Volunteer
 
Posts: 9429
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: StoreURLAs error object variable not set

Postby Muthuvel » Sun Jun 21, 2020 7:42 am

@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   Expand viewCollapse view
Doc = StarDesktop.loadComponentFromURL(Url, "MyFrame", SearchFlags, Dummy)


Now I have suppied the password with the FileProp array as follows
Code: Select all   Expand viewCollapse view
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
Muthuvel
 
Posts: 12
Joined: Sat Jun 20, 2020 7:42 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests