Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
rangos_exportar_rapido formato:=xlCSV, abrir_gretl:=True, transponerb:=False
Sub rangos_a_gretl_y_transponer()
rangos_exportar_rapido formato:=xlCSV, abrir_gretl:=True, transponerb:=True
Sub rangos_exportar_rapido(formato As XlFileFormat, Optional abrir_gretl As Boolean, Optional transponerb As Boolean, Optional filtro As String)
'export Macro
Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3
Dim fPath As String
Dim nArchivo As String
'Dim pregunta_abrir_gretl
Dim retval
Dim argumento As String, gretl_path As String
'Dim transponer
'Dim transponerb As Boolean
If (Not ActiveWorkbook Is Nothing) Then
fPath = ActiveWorkbook.path
nArchivo = ActiveWorkbook.FullName
If (Not Selection Is Nothing) Then
If TypeName(Selection) = "Range" Then
If Selection.Count >= 4 Then
'transponer = MsgBox("¿Transponer el rango?", vbYesNo)
'If transponer = vbYes Then
' transponerb = True
'Else
' transponerb = False
'End If
sp_Speed
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Transpose:=transponerb ', Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.DisplayAlerts = False
If fPath = "" Then nArchivo = Environ$("USERPROFILE") & "\My Documents\" & "archivo no guardado del " & Format(Date, "yyyy.mm.dd, a las ") & Format(Time, "hh.mm") & " hs"
ActiveWorkbook.SaveAs Filename:=nArchivo & " exportado.csv", FileFormat:=formato, CreateBackup:=False
ActiveWorkbook.Close
Application.DisplayAlerts = True
sp_Unspeed
'pregunta_abrir_gretl = MsgBox("¿Abrir Gretl?", vbYesNo)
If abrir_gretl = True Then
'Debug.Print """" & nArchivo & " exportado.csv"""
'Debug.Print fPath
argumento = """" & nArchivo & " exportado.csv" & """"
If filtro <> "" Then argumento = """" & filtro & """"
Debug.Print argumento
gretl_path = Environ("programfiles") & "\gretl\gretlw32.exe"
retval = ShellExecute(0, "open", gretl_path, argumento, fPath, SW_SHOWMAXIMIZED)
End If
End If
End If
End If
End If
End Sub