[RESUELTO] Mudar Macro de Excel a Libreoffice

Desarrollo de Macros y programación en UNO, usar las API, llamar programas externos...
Responder
nicodavid
Mensajes: 10
Registrado: Vie May 31, 2019 8:37 pm

[RESUELTO] Mudar Macro de Excel a Libreoffice

Mensaje por nicodavid »

Buenas tardes, me gustaria saber si ¿hay alguna forma de pasar una macro de Excel a Libreoffice?.
El tema es que al abrir el archivo que tiene la macro por primera vez en LibO, la macro funciona (aparentemente). Pero al cerrarlo y volverlo a abrir , deja de funcionar y da errores por todos lados.
lo que hace la macro es: si identifica que en la columna (2) de la Hoja("Demo") hay una "I", Entonces copia los valores de las columnas siguientes, en una planilla del mismo libro llamada "VALE2" (esta planilla es similar a un remito).
Al copiar todos los datos, imprime el rango de impresion seleccionado de la Hoja "VALE2".
una vez impreso, Los datos de "VALE2" quedan en vacio , para que se copie otra columna que contenga "I", y asi sucesivamente, hasta encontrarse con vacio en la columna (2) de la Hoja "Demo".
Una vez finalizado todo, todas las columnas que tenian la letra "I", Cambian su Valor por la Letra "P" (para que cuando se vuelva a ejecutar la macro, no vuelva a imprimir lo que ya esta impreso).
Dejo el Codigo pegado abajo.(vale aclarar que fue una de las primeras macro que realice y como funciono, nunca mas la volvi a mejorar).

Sub VALE()
'
' VALE Macro
' IMPRESION DE VALES
'
' Acceso directo: Ctrl+Mayús+O
With Application
.Calculation = xlAutomatic

End With
i = 5
u_STOP = 0
Do While u_STOP = 0
If Sheets("Demo").Cells(i, 2) = "I" Then
Sheets("VALE2").Cells(1, 9) = Sheets("Demo").Cells(i, 1)
Sheets("VALE2").Cells(2, 9) = Sheets("Demo").Cells(i, 5)
Sheets("VALE2").Cells(3, 9) = Sheets("Demo").Cells(i, 6)
Sheets("VALE2").Cells(4, 2) = Sheets("Demo").Cells(i, 8)
Sheets("VALE2").Cells(4, 6) = Sheets("Demo").Cells(i, 9)
Sheets("VALE2").Cells(4, 9) = Sheets("Demo").Cells(i, 7)
Sheets("VALE2").Cells(5, 2) = Sheets("Demo").Cells(i, 10)
Sheets("VALE2").Cells(5, 6) = Sheets("Demo").Cells(i, 11)
Sheets("VALE2").Cells(5, 9) = Sheets("Demo").Cells(i, 12)
Sheets("VALE2").Cells(8, 2) = Sheets("Demo").Cells(i, 13)
Sheets("VALE2").Cells(8, 4) = Sheets("Demo").Cells(i, 14)
Sheets("VALE2").Cells(8, 8) = Sheets("Demo").Cells(i, 15)
Sheets("VALE2").Cells(9, 9) = Sheets("Demo").Cells(i, 29)
Sheets("VALE2").Cells(8, 9) = Sheets("Demo").Cells(i, 17)
Sheets("VALE2").Cells(10, 2) = Sheets("Demo").Cells(i, 19)
Sheets("VALE2").Cells(11, 2) = Sheets("Demo").Cells(i, 20)
Sheets("VALE2").Cells(10, 4) = Sheets("Demo").Cells(i, 3)
Sheets("VALE2").Cells(12, 2) = Sheets("Demo").Cells(i, 21)
Sheets("VALE2").Cells(13, 2) = Sheets("Demo").Cells(i, 22)
Sheets("VALE2").Cells(14, 2) = Sheets("Demo").Cells(i, 23)
Sheets("VALE2").Cells(15, 2) = Sheets("Demo").Cells(i, 24)
Sheets("VALE2").Cells(15, 5) = Sheets("Demo").Cells(i, 27)
Sheets("VALE2").Cells(15, 9) = Sheets("Demo").Cells(i, 28)
Sheets("VALE2").Select

Range("A1 : D5").Select
ActiveSheet.PageSetup.Orientation = xlPortrait
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("VALE2").Cells(1, 9) = ""
Sheets("VALE2").Cells(2, 9) = ""
Sheets("VALE2").Cells(3, 9) = ""
Sheets("VALE2").Cells(4, 2) = ""
Sheets("VALE2").Cells(4, 6) = ""
Sheets("VALE2").Cells(4, 9) = ""
Sheets("VALE2").Cells(5, 2) = ""
Sheets("VALE2").Cells(5, 6) = ""
Sheets("VALE2").Cells(5, 9) = ""
Sheets("VALE2").Cells(8, 2) = ""
Sheets("VALE2").Cells(8, 4) = ""
Sheets("VALE2").Cells(8, 8) = ""
Sheets("VALE2").Cells(8, 9) = ""
Sheets("VALE2").Cells(9, 9) = ""
Sheets("VALE2").Cells(10, 2) = ""
Sheets("VALE2").Cells(11, 2) = ""
Sheets("VALE2").Cells(10, 4) = ""
Sheets("VALE2").Cells(12, 2) = ""
Sheets("VALE2").Cells(13, 2) = ""
Sheets("VALE2").Cells(14, 2) = ""
Sheets("VALE2").Cells(15, 2) = ""
Sheets("VALE2").Cells(15, 5) = ""
Sheets("VALE2").Cells(16, 9) = ""
Sheets("Demo").Select

End If


If Sheets("Demo").Cells(i, 2) = "" Then u_STOP = 1

i = i + 1
Loop
Sheets("Demo").Select
E = 5
u_STOP = 0
Do While u_STOP = 0
If Cells(E, 2) = "I" Then Cells(E, 2) = "P"
If Cells(E, 2) = "" Then u_STOP = 1
E = E + 1
Loop
Sheets("Demo").Select





End Sub
Última edición por nicodavid el Mié Jun 05, 2019 6:26 pm, editado 1 vez en total.
OpenOffice 3.1 / Windows
Avatar de Usuario
fornelasa
Mensajes: 3268
Registrado: Jue Feb 17, 2011 8:30 pm
Ubicación: Estado de México, México.

Re: Mudar Macro de Excel a Libreoffice

Mensaje por fornelasa »

Hice pruebas con tu macro en LibreOffice y no me dio problema ni marcó error alguno.
Obviamente al inicio del modulo donde esta la macro VALE() debe colocarse

Código: Seleccionar todo

Option VBASupport 1
Sub VALE()
-------
-------
End Sub
Saludos, Federico.
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
Avatar de Usuario
fornelasa
Mensajes: 3268
Registrado: Jue Feb 17, 2011 8:30 pm
Ubicación: Estado de México, México.

Re: [RESUELTO] Mudar Macro de Excel a Libreoffice

Mensaje por fornelasa »

Esta macro parece ser una traducción aproximada de tu macro Excel.

Código: Seleccionar todo

Sub VALE()
' VALE Macro
' IMPRESION DE VALES

     docto = ThisComponent
      Demo = docto.Sheets.getByName("Demo")
     VALE2 = docto.Sheets.getByName("VALE2")
    

  document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
 dim args1(0) as new com.sun.star.beans.PropertyValue
     args1(0).Name = "AutomaticCalculation"
     args1(0).Value = true
 dispatcher.executeDispatch(document, ".uno:AutomaticCalculation", "", 0, args1())

        i = 4
   u_STOP = 0
   Do While u_STOP = 0
   If Demo.getCellByPosition(1, i).String = "I" Then

VALE2.getCellByPosition(8,0).Formula = Demo.getCellByPosition(0,i).Formula
VALE2.getCellByPosition(8,1).Formula = Demo.getCellByPosition(4,i).Formula
VALE2.getCellByPosition(8,2).Formula = Demo.getCellByPosition(5,i).Formula
VALE2.getCellByPosition(1,3).Formula = Demo.getCellByPosition(7,i).Formula
VALE2.getCellByPosition(5,3).Formula = Demo.getCellByPosition(8,i).Formula
VALE2.getCellByPosition(8,3).Formula = Demo.getCellByPosition(6,i).Formula
VALE2.getCellByPosition(1,4).Formula = Demo.getCellByPosition(9,i).Formula
VALE2.getCellByPosition(5,4).Formula = Demo.getCellByPosition(10,i).Formula
VALE2.getCellByPosition(8,4).Formula = Demo.getCellByPosition(11,i).Formula
VALE2.getCellByPosition(1,7).Formula = Demo.getCellByPosition(12,i).Formula
VALE2.getCellByPosition(3,7).Formula = Demo.getCellByPosition(13,i).Formula
VALE2.getCellByPosition(7,7).Formula = Demo.getCellByPosition(14,i).Formula
VALE2.getCellByPosition(8,8).Formula = Demo.getCellByPosition(28,i).Formula
VALE2.getCellByPosition(8,7).Formula = Demo.getCellByPosition(16,i).Formula
VALE2.getCellByPosition(1,9).Formula = Demo.getCellByPosition(18,i).Formula
VALE2.getCellByPosition(1,10).Formula = Demo.getCellByPosition(19,i).Formula
VALE2.getCellByPosition(3,9).Formula = Demo.getCellByPosition(2,i).Formula
VALE2.getCellByPosition(1,11).Formula = Demo.getCellByPosition(20,i).Formula
VALE2.getCellByPosition(1,12).Formula = Demo.getCellByPosition(21,i).Formula
VALE2.getCellByPosition(1,13).Formula = Demo.getCellByPosition(22,i).Formula
VALE2.getCellByPosition(1,14).Formula = Demo.getCellByPosition(23,i).Formula
VALE2.getCellByPosition(4,14).Formula = Demo.getCellByPosition(26,i).Formula
VALE2.getCellByPosition(8,14).Formula = Demo.getCellByPosition(27,i).Formula

docto.CurrentController.Select(VALE2.getCellRangeByName("A1:D5"))

dispatcher.executeDispatch(document, ".uno:PrintDefault", "", 0, Array())

VALE2.getCellByPosition(8,0).String = ""
VALE2.getCellByPosition(8,1).String = ""
VALE2.getCellByPosition(8,2).String = ""
VALE2.getCellByPosition(1,3).String = ""
VALE2.getCellByPosition(5,3).String = ""
VALE2.getCellByPosition(8,3).String = ""
VALE2.getCellByPosition(1,4).String = ""
VALE2.getCellByPosition(5,4).String = ""
VALE2.getCellByPosition(8,4).String = ""
VALE2.getCellByPosition(1,7).String = ""
VALE2.getCellByPosition(3,7).String = ""
VALE2.getCellByPosition(7,7).String = ""
VALE2.getCellByPosition(8,7).String = ""
VALE2.getCellByPosition(8,8).String = ""
VALE2.getCellByPosition(1,9).String = ""
VALE2.getCellByPosition(1,10).String = ""
VALE2.getCellByPosition(3,9).String = ""
VALE2.getCellByPosition(1,11).String = ""
VALE2.getCellByPosition(1,12).String = ""
VALE2.getCellByPosition(1,13).String = ""
VALE2.getCellByPosition(1,14).String = ""
VALE2.getCellByPosition(4,14).String = ""
VALE2.getCellByPosition(8,15).String = ""
docto.CurrentController.Select(Demo.getCellRangeByName("A1"))
End If


If Demo.getCellByPosition(i, 1).String = "" Then u_STOP = 1

i = i + 1
Loop
docto.CurrentController.Select(Demo.getCellRangeByName("A1"))
E = 4
u_STOP = 0
Do While u_STOP = 0
If Demo.getCellByPosition(1,E).String = "I" Then Demo.getCellByPosition(1,E).String = "P"
If Demo.getCellByPosition(1,E).String = "" Then u_STOP = 1
E = E + 1
Loop
docto.CurrentController.Select(Demo.getCellRangeByName("A1"))
End Sub
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
Responder