Hi. This might come handy for people working with heterogeneous data before
passing it to gretl. I'm using them along the scripts discussed earlier on
this list for making seasonal adjustment of several variables at once, but
of course using this + your custom scripts could help you in analysing your
excel data faster with gretl if that's how you get or preprocess your
information before being ready to using it.
You select a range in excel, press the hotkey assigned and gretl opens with
the data you selected. If the series are in the form of rows instead of
columns, use the second macro "rangos_a_gretl_y_transponer" which transposes
the range before sending it to gretl. The macros are kind of robust, they
work on excel 2010 32bit + windows 7 and excel 2007 + XP and vista + 2007.
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
Sub rangos_a_gretl()
rangos_exportar_rapido formato:=xlCSV, abrir_gretl:=True,
transponerb:=False
End Sub
Sub rangos_a_gretl_y_transponer()
rangos_exportar_rapido formato:=xlCSV, abrir_gretl:=True,
transponerb:=True
End Sub
Sub rangos_exportar_rapido(formato As XlFileFormat, Optional abrir_gretl As
Boolean, Optional transponerb As Boolean, Optional filtro As String)
'based upon
http://www.ozgrid.com/forum/showthread.php?t=76720
'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