Page 1 of 1

[Solved] loadComponentFromURL Error

Posted: Mon Nov 12, 2012 7:03 pm
by jefferyweeks
Hello All,

I have a Calc document that contains macros. The macros run when the file is opened. What I am trying to do is open the document with a vb script. I have written the following code:

Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")

'Create the Desktop
Set objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")

'Open a new empty writer document
Dim args()
Set objDocument= objDesktop.loadComponentFromURL("File:///C:\Users\Jeff Weeks\Desktop\Test.ods","_blank", 0, Array())

The issue with this is that it is opening the document up with the file name being the full path name (File:///C:\Users\Jeff Weeks\Desktop\Test.ods). When i then try to save it, I get the following error: "Error saving the document C:\Users\Jeff Weeks\Desktop\Test: The operation on \\.\ was started with an invalid parameter."

Does anyone know how to open the document via vbs so that the document is opened with just the name (Test.ods)?

Thank you in advance for your help!

Re: loadComponentFromURL Error

Posted: Mon Nov 12, 2012 7:39 pm
by B Marcelly
Hi,
jefferyweeks wrote:

Code: Select all

'Open a new empty writer document
Dim args()
Set objDocument= objDesktop.loadComponentFromURL("File:///C:\Users\Jeff Weeks\Desktop\Test.ods","_blank", 0, Array())
  • The comment in your code contradicts your code.
  • Learn to create a real URL. This is more complex than you think :

Code: Select all

' Windows address
File:///C:\Users\Jeff Weeks\Desktop\Test.ods
' equivalent URL
file:///C:/Users/Jeff%20Weeks/Desktop/Test.ods

Re: loadComponentFromURL Error

Posted: Mon Nov 12, 2012 9:13 pm
by jefferyweeks
Bernard,

You're the man. That worked perfectly.

Thank you,
Jeff