Hola Alejandro
te contesto el mensaje personal en la lista users para que quede
archivado (siempre es posible que luego le sirva a alguien)
Alejandro Rivas escribió:
Saludos.
Necesito ayuda para hacer lo siguiente:
Hay dos hojas abiertas y luego con la macro de una abro otro. En total 3.
a) Cómo podría pasar entre la ventana de un archivo y otro
b) Cómo podría insertar la letra "A" en la celda A1 de los tres archivos
abiertos.
Sub RevisaArchivos
Dim oDoc, document, Oarchivo3
Dim archivo3
Dim oDesk
oDoc=Thiscomponent
document = ThisComponent.CurrentController.Frame
archivo3="file:///DATA/EXMAY1.SXC"
oDesk = createUnoService("com.sun.star.frame.Desktop")
Dim NoArg()
Oarchivo3=oDesk.loadComponentFromURL(archivo3,"_blank",0,Array())
oDoc.CurrentController.Frame.ContainerWindow.toFront() ' no funciona
'' se queda el botón de la ventana parpadeando sin salir al frente
'' oDoc.CurrentController.Frame.Activate() ' igual efecto
msgbox oDoc.Sheets(2).Name ' Pero si se muestra el nombre de la Hoja2
''del archivo de la macro
end sub
Gracias anticipadas
lo que sucede es que estás empleando los métodos equivocados.
Como te comenté a la mañana (de Argentina), si quieres que un componente
pase a primer plano del escritorio, es decir: que reciba el foco, debes
emplear el método setFocus()
http://api.openoffice.org/docs/common/ref/com/sun/star/awt/XWindow.html#setFocus
DESDE LUEGO, si lo cargas con el método loadComponentFromURL empleando
parámetros por defecto, el documento abierto recibe automáticamente el
foco (tal cual sucede en la interfaz gráfica.)
La explicación sobre la diferencia entre lo que intentas en tu macro y
setFocus():
http://api.openoffice.org/docs/DevelopersGuide/OfficeDev/OfficeDev.xhtml#1_1_3_2_1_3_Frame_Actions
Cito:
Several actions take place at a frame. The context of viewable
components can change, a frame may be activated or the
relationship between frame and component may be altered. For
instance, when the current selection in a document has been
changed, the controller informs the frame about it by calling
contextChanged(). The frame then tells its frame action
listeners that the context has changed. The frame action
listeners are also informed about changes in the relationship
between the frame and component, and about frame activation. The
corresponding XFrame methods are:
void contextChanged ();
[oneway] void activate ();
[oneway] void deactivate ();
boolean isActive ();
[oneway] void addFrameActionListener ( [in]
com::sun::star::frame::XFrameActionListener xListener );
[oneway] void removeFrameActionListener ( [in]
com::sun::star::frame::XFrameActionListener xListener );
The *method* *activate*() [PRESTA TENCIÓN AQUÍ!!!!] makes the
given frame the active frame in its parent container. If the
parent is the desktop frame, this makes the associated component
the current component. *However*, *this is not reflected* in the
*user interface* by making the corresponding window the top
window. If the container of the active frame is to be the top
window, use setFocus() at the com.sun.star.awt.XWindow
interface
of the container window.
Sobre XWindow:
http://api.openoffice.org/docs/DevelopersGuide/OfficeDev/OfficeDev.xhtml#1_1_3_5_1_XWindow
Creo que esta vez no está tan chino, para "poner el foco en un
documento", que aparezca en primer plano en el escritorio, debes hacer
que la ventana que lo contiene sea la "principal" (TOP) en la jerarquía
de ventanas del escritorio (Desktop).
¿Cómo?
oDoc.CurrentController.Frame.ContainerWindow.setFocus()
donde oDoc puede ser una referencia al documento activo, o un documento
que has cargado, etc.
EL siguiente ejemplo crea seis documentos nuevos (de casi cada
aplicación de OOo) y guarda una referencia a cada uno de ellos. Entre
cada doc. espera 2000 milisegs. Luego con un bucle, van recibiendo el
foco, esperando 3000 milisegs. entre cada acción:
Sub Foco_BUCLE_WAIT
oDocActual = ThisComponent
oDocCalNuevo = FN_DocNuevo("scalc") : Wait 2000
oDocDrawNuevo = FN_DocNuevo("sdraw") : Wait 2000
oDocWriterNuevo = FN_DocNuevo("swriter") : Wait 2000
oDocImpressNuevo = FN_DocNuevo("simpress") : Wait 2000
oDocMathNuevo = FN_DocNuevo("smath") : Wait 2000
oDocBaseNuevo = FN_DocNuevo("sdatabase") : Wait 2000
Dim oDocs()
oDocs = Array(oDocActual, oDocCalNuevo, oDocDrawNuevo, _
oDocWriterNuevo,oDocImpressNuevo, oDocMathNuevo, _
oDocBaseNuevo)
For n = 0 to UBound(oDocs)
WAIT 3000
oDocs(n).CurrentController.Frame.ContainerWindow.setFocus
Next
End Sub
Function FN_DocNuevo (sTipoDoc as String, Optional MediaDescriptor() )
If IsMissing(MediaDescriptor()) then MediaDescriptor() = Array()
FN_DocNuevo = StarDesktop.loadComponentFromURL(_
"private:factory/" & sTipoDoc , "_default", 0,_
MediaDescriptor())
End Function
Para que funcione como debe, ejecútalala y quédate cruzado de brazos: el
efecto será igual a ir haciendo clic en cada doc. la barra de tareas.
Te adjunto un documento (espero que tengas lugar en tu mail, pues el
otro día intente enviarte la referencia API en CHM y no cabía) Calc con
este ejemplo, además te muestro como enumerar los componentes del
Desktop y preguntar por su servicio (es decir, qué tipo de doc. es) y su
URL.
Saludos,
Ariel
La Plata
Argentina.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]