Hola, Raquel -
El problema puede deberse a que Excel no puede encontrar el archivo de hoja de cálculo solicitado.
¿Qué estás intentando lograr? ¿Abrir una hoja de cálculo de Excel existente o crear una nueva?
Si quieres abrir una hoja de cálculo existente, debes asignar la colección Workbooks a otro OLEObject para poder manipular los libros de trabajo dentro de la hoja de cálculo. Aquí hay un ejemplo que abre una hoja de cálculo de Excel y luego obtiene y muestra todas las propiedades integradas del documento:
[Translation]
Hi, Raquel -
The problem may be due to Excel not being able to find the requested spreadsheet file.
What are you trying to accomplish? Open an existing Excel spreadsheet or create a new one?
If you are wanting to open an existing spreadsheet, you need to assign the Workbooks collection to another OLEObject in order that you may manipulate the workbooks within the spreadsheet. Here is an example that opens an Excel spreadsheet, then obtains and displays all of the built-in document properties:
// Tests how to access built-in document properties in Excel.
Integer li_rc, li_count, li_index
String ls_msg, ls_prop_name, ls_prop_value, ls_last_author_prev
OLEObject lole_excelapp, lole_workbook, lole_builtin
// Establish and OLE connection to the Excel application.
lole_excelapp = CREATE OLEObject
li_rc = lole_excelapp.ConnectToNewObject("Excel.Application")
// Open an Excel workbook (a .xlsx file).
lole_workbook = CREATE OLEObject
lole_workbook = lole_excelapp.Workbooks.Open("C:\Test.xlsx") // <--- Specify the path/name of an Excel spreadsheet here.
// How many built-in document properties are there in the collection?
li_count = lole_workbook.BuiltinDocumentProperties.Count
//MessageBox("Built-In Document Properties Count",String(li_count))
// Create an OLE object to access/modify a document property.
lole_builtin = CREATE OLEObject
ls_msg = ""
// Obtain the name of each built-in document property and if possible,
// its value.
//
// The use of Try/Catch statements is required, because Excel will throw a runtime error
// if you try to obtain the value of a document property that does not have a value.
For li_index = 1 To li_count
// Obtain the next built-in document property from the collection.
lole_builtin = lole_workbook.BuiltinDocumentProperties(li_index)
// Get the name of this built-in document property.
Try
ls_prop_name = lole_builtin.Name
Catch (RuntimeError lrte_name1)
ls_prop_name = "(unknown)"
End Try
// Get the value of this built-in document property.
Try
ls_prop_value = lole_builtin.Value
Catch (RuntimeError lrte_value1)
ls_prop_value = "(unknown)"
End Try
// List up to ten built-in document property name/value pairs at a time.
If Mod(li_index,10) <> 1 Then ls_msg += "~r~n~r~n"
ls_msg += String(li_index,"00") + " " + ls_prop_name + "~r~n~t" + ls_prop_value
If Mod(li_index,10) = 0 Then
MessageBox("Built-in Document Properties",ls_msg)
ls_msg = ""
End If
Next
// Are there any remaining built-in document properties that need to be displayed?
If ls_msg <> "" Then
MessageBox("Built-in Document Properties",ls_msg)
ls_msg = ""
End If
// We're finished with the built-in document property OLE object.
DESTROY lole_builtin
// Close the Excel workbook.
lole_excelapp.Workbooks.Close
DESTROY lole_workbook
// Clean up before finishing.
DESTROY lole_excelapp
Return 0
Saludos cordiales, John
Muchas gracias por tu contestación. He estado probando la opción que me comentas y sigue sin funcionar. Da el mismo error en la apertura, teniendo en cuenta tus indicaciones.
Un saludo y de nuevo gracias