[Solved] loadComponentFromURL Error

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jefferyweeks
Posts: 2
Joined: Mon Nov 12, 2012 6:55 pm

[Solved] loadComponentFromURL Error

Post 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!
Last edited by Hagar Delest on Mon Nov 12, 2012 10:22 pm, edited 1 time in total.
Reason: tagged [Solved].
Open Office 3.4.1 on Windows 7
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: loadComponentFromURL Error

Post 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
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
jefferyweeks
Posts: 2
Joined: Mon Nov 12, 2012 6:55 pm

Re: loadComponentFromURL Error

Post by jefferyweeks »

Bernard,

You're the man. That worked perfectly.

Thank you,
Jeff
Open Office 3.4.1 on Windows 7
Post Reply