Página 1 de 1

Traducir Codigo de macro de Excel en basic

Publicado: Lun Jun 19, 2017 10:13 pm
por JRAVLES
Buenas Tardes,
Estoy intentando traducir un codigo de un macro de excel de un libro que exporta una hoja a un archivo csv, pero no me acaba de funcionar.
El codigo es el siguiente
Sub ExportCSV()

Application.Calculation = xlAutomatic
Application.DisplayAlerts = False
Dim path As String: path = ActiveWorkbook.path
Dim name As String:

Range("AE1").FormulaR1C1 = "=+""(CSV) ""&IF(R[7]C[-23]<>"""",TEXT(R[7]C[-23],""aaaa-mm-dd""),"""")&"" Estado tienda ""& R[5]C[-23]" ' &"" - ""&R[5]C[-18]"
name = Range("AE1").Text
Range("AE1").Clear

Sheets("Exportar a CSV").Visible = True
Sheets("Exportar a CSV").Activate
Sheets("Exportar a CSV").Select
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.name = "CSV"


i = 1
Do While Sheets("Exportar a CSV").Range("A" & i).Text <> ""

Sheets("Exportar a CSV").Select
Range("A" & i).Select
Selection.Copy
Sheets("CSV").Select
Range("A" & i).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

i = i + 1
Loop


Application.CutCopyMode = False
Sheets("CSV").Copy
Cells.Replace What:=",", Replacement:="'", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:=Chr(10), Replacement:=" ", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
ActiveWorkbook.SaveAs path & "\" & name & ".csv", xlCSV, CreateBackup:=False
ActiveWorkbook.Close (False)

Sheets("Exportar a CSV").Visible = False
Sheets("CSV").Delete
Sheets("CLIENTE").Select

End Sub

Alguien me puede echar un cable

Re: Traducir Codigo de macro de Excel en basic

Publicado: Lun Jun 19, 2017 10:49 pm
por mauricio
Usa EasyDev: http://easydev.readthedocs.io/en/latest ... export-csv

Código: Seleccionar todo

util = createUnoService("org.universolibre.EasyDev")

range = ThisComponent.CurrentSelection

path = "/home/USER/test.csv"
data = range.getDataArray()
options = Array()

util.exportCSV(path, data, options)
Saludos

Re: Traducir Codigo de macro de Excel en basic

Publicado: Mar Jun 20, 2017 6:45 pm
por fornelasa
Adicionalmente: y muy ligeramente lento y con unos leves cambios parece que tu macro funciona así:
da clic en expandir vista, selecciona y copia.

Código: Seleccionar todo

Option VBASupport 1
Sub ExportCSV()
doc = ThisComponent.CurrentController
hojas = ThisComponent.getSheets()
Application.Calculation = xlAutomatic
Application.DisplayAlerts = False
Dim path As String: path = ActiveWorkbook.path
Dim name As String:

Range("AE1").FormulaR1C1 = "=+""(CSV) ""&IF(R[7]C[-23]<>"""",TEXT(R[7]C[-23],""aaaa-mm-dd""),"""")&"" Estado tienda ""& R[5]C[-23]" ' &"" - ""&R[5]C[-18]"


name = Range("AE1").Text
Range("AE1").Clear

Sheets("Exportar a CSV").Visible = True
Sheets("Exportar a CSV").Activate
Sheets("Exportar a CSV").Select
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.name = "CSV"


i = 1
Do While Sheets("Exportar a CSV").Range("A" & i).Text <> ""

Sheets("Exportar a CSV").Select
Range("A" & i).Select
Selection.Copy
Sheets("CSV").Select
Range("A" & i).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

i = i + 1
Loop


Application.CutCopyMode = False
Sheets("CSV").Copy
Cells.Replace What:=",", Replacement:="'", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:=Chr(10), Replacement:=" ", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
ActiveWorkbook.SaveAs path & "\" & name & ".csv", xlCSV, CreateBackup:=False
ActiveWorkbook.Close (False)


hojas.getByName("Exportar a CSV").IsVisible = False
hojas.removeByName("CSV")
doc.select(hojas.getByName("CLIENTE").getCellRangeByName("A1"))


End Sub

Re: Traducir Codigo de macro de Excel en basic

Publicado: Mar Jun 20, 2017 7:08 pm
por JRAVLES
Muchas gracias por vuestra ayuda

Re: Traducir Codigo de macro de Excel en basic

Publicado: Mar Jun 20, 2017 8:34 pm
por fornelasa
Si consideras que en este tema https://forum.openoffice.org/es/forum/v ... 50&t=13002 y en este mismo se han resuelto tus dudas entonces por favor marcarlos como [RESUELTO]
Aquí nos dicen como hacerlo:
https://forum.openoffice.org/es/forum/v ... f=3&t=2668
Saludos.