Basic error, save/overwrite document

Using Andrew’s code as below I get this error
BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: cannot coerce argument type during corereflection call:
arg no.: 1 expected: “[]com.sun.star.beans.PropertyValue” actual: “void”.

Can anyone explain the error please and what I need to correct?

Dim oProp(0) As New com.sun.star.beans.PropertyValue
Dim sUrl As String
sUrl = "file:///<complete/path/To/New/document>"
REM Set this to True if you want to overwrite the document.
oProp(0).Name = "Overwrite"
oProp(0).Value = True
oDoc.storeAsURL(sUrl, oProp())

What line are you using for sUrl =?

Please copy and paste the code from your macro, do not re-type it, nor copy from Andrew’s book. It actually looks as if you made some typo, and used a wrong oProp variable name where you called storeAsURL.

Something similar to:

Dim oProp(0) As New com.sun.star.beans.PropertyValue
Dim sUrl As String
sUrl = "file:///<complete/path/To/New/document>"
REM Set this to True if you want to overwrite the document.
oProp(0).Name = "Overwrite"
oProp(0).Value = True
oDoc.storeAsURL(sUrl, aProp())

(note the oProp used where the variable is defined/filled, but aProp where it’s used).
Additionally, I suspect that you are using Option VBASupport 1. This changes the error in the case that I outlined above into what you see.

fly C:\foo.ods

mike - not understanding. My code is exactly as taken from Andrew. Not using that option.

Dim oProp(0) As New com.sun.star.beans.PropertyValue
Dim sUrl As String
sUrl = "C:\foo.ods"
REM Set this to True if you want to overwrite the document.
oProp(0).Name = "Overwrite"
oProp(0).Value = True
ThisComponent.storeAsURL(sUrl, oProp())

The argument must be an URL, not just some local path. Basic allows you to use ConvertToURL for that.

But the error in this case would be different:

BASIC runtime error.
‘1’
An exception occurred
Type: com.sun.star.task.ErrorCodeIOException
Message: SfxBaseModel::impl_store <C:\foo.ods> failed: 0x81a(Error Area:Io Class:Parameter Code:26).

OK - so you are saying Andrew’s code is wrong?

It would be much quicker to show me the correct way to overwrite a file in a LO Basic macro!

No, I say that your code is wrong. It must provide an URL, and you actually provide a local path.

Dim oProp(0) As New com.sun.star.beans.PropertyValue
Dim sUrl As String
sUrl = ConvertToURL("C:\foo.ods")
REM Set this to True if you want to overwrite the document.
oProp(0).Name = "Overwrite"
oProp(0).Value = True
ThisComponent.storeAsURL(sUrl, oProp())

Fine - I can see that, and yes, I get the same error as you by converting to a Url. So, what is going wrong?

Any chance of ANYONE helping with the correct macro?

Still hoping there is someone who can help here. This thread [Solved] Error with storeAsURL: can’t figure out the reason (View topic) • Apache OpenOffice Community Forum talks about a ‘filter;’ but I do not have one. This thread talks about a bug in LO. https://bugs.documentfoundation.org/show_bug.cgi?id=60237

Try to run the macro saving the file in another folder or subfolder distinct of the root folder.

sUrl = ConvertToURL("C:\Test\foo.ods")

Thanks, gbp, but I have sorted it.