miércoles, febrero 22, 2017

Instalación de Java 8 automáticamente en distribuciones tipo Debian

Bajamos el paquete Java 8 de la web de Oracle y aceptamos la licencia de uso automáticamente en distribuciones tipo Debian.


# Install Java 8 automatically 
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
sudo apt-get -y install oracle-java8-installer
java -version

martes, julio 21, 2015

Ajustar el tamaño de las 1000 primeras filas a un tamaño determinado.

Ajustar el tamaño de las 1000 primeras filas a un tamaño determinado.

Sub fixRowHeights()
   For i = 1 To 1000
      ThisWorkbook.ActiveSheet.Rows(i).RowHeight = 19
   Next i
End Sub

viernes, julio 17, 2015

Función que genera hipervínculos a las pestañas del Libro si estas existen.

'UTIL
Public Function WorksheetExists(ByVal WorksheetName As String) As Boolean
   On Error Resume Next
      WorksheetExists = (Sheets(WorksheetName).Name <> "")
   On Error GoTo 0
End Function


Sub GenHyperlinks()
     Dim i As Long
     Sheets("Taller").Activate
     i = 2
     'El link va en el primer registro de la tabla
     While Range("A" & i).Value <> ""
        If Range("D" & i).Value = "1" Then
           'Si ya tiene enlace no recrear
           If Range("A" & i).Hyperlinks.Count = 0 Then
              'Si la hoja existe crear el enlace
              If WorksheetExists(Range("A" & i).Value) Then
                 'Create link
                 Range("A" & i).Hyperlinks.Add _
                 Anchor:=Range("A" & i), _
                 Address:="", _
                 SubAddress:=Range("A" & i).Value & "!A1", _
                 ScreenTip:=Range("A" & i).Value, _
                 TextToDisplay:=Range("A" & i).Value
              End If
           End If
        End If
        i = i + 1
        DoEvents
     Wend
End Sub


VBA - Convertir enlaces absolutos en enlaces relativos

Función que convierte todos los enlaces absolutos de un archivo a enlaces relativos. (Sólo usar cuando el archivo sólo contenga enlaces a él mismo) Así podemos modificar el nombre y la ubicación del archivo sin que fallen los hipervínculos.

'Convierte en relativos todos los enlaces de un Libro eliminando las referencias externas a otros archivos.
Sub FixHyperlinks()
   Dim hyp As Hyperlink
   Dim sh As Worksheet
   
   For Each sh In ThisWorkbook.Worksheets
      For Each hyp In sh.Hyperlinks
         hyp.Address = ""
      Next hyp
   Next sh
   
   MsgBox ("Los hipervínculos se actualizaron corréctamente")
   
End Sub


martes, noviembre 18, 2014

Formatear celdas en Flexigrid


$(".flexme5").flexigrid({
                title: 'Overview by category', 
                url: 'PnLCalculations.asmx/GetRowData2',
                dataType: 'json',
                method: 'post',
                params: [{ name: 'uid', value: '<%= cSession.UserWeb %>' },
                         { name: 'entityId', value: '<%= cSession.EntityCode %>' },
                         { name: 'period', value: '<%= ddlPeriod.Text %>' },
                         { name: 'secondGroupOrder', value: 'Category' }
                         ],
                colModel: [
                { display: 'Folders Shortname', name: 'col01', width: 100, sortable: true, draggable: false, align: 'left' },
                { display: 'Category', name: 'col02', width: 100, sortable: true, draggable: false, align: 'left' },
                { display: 'Sum', name: 'col03', width: 100, sortable: true, draggable: false, align: 'right' },
                { display: 'Count', name: 'col04', width: 100, sortable: true, draggable: false, align: 'right' }
                ],
                sortname: "row01",
                sortorder: "asc",
                usepager: true,
                autoload: true,
                resizable: false,
                singleSelect: true,
                useRp: false,
                rp: 25,
                width: twidth,
                height: 505,
                preProcess: function(data) {
                    $.each(data.rows, function(i, row) {
                       if (parseInt(row.col03)<0) {
                          row.col03='

'+row.col03+'

'; } if (parseInt(row.col03)>0) { row.col03='

'+row.col03+'

'; } }); return data; }, });

Función para convertir un número de columna en su letra en Excel

Función VBA para convertir un número de columna en su nombre en letras, para usarlo en Excel.

Function numberToColumnName(ByVal colNumber As Integer) As String
   Dim dividend As Integer
   Dim columnName As String
   Dim module As Integer
   
   dividend = colNumber
   
   While (dividend > 0)
      module = (dividend - 1) Mod 26
      columnName = Chr(65 + module) + columnName
      
      dividend = (dividend - module) / 26
   Wend
   numberToColumnName = columnName
End Function

jueves, agosto 28, 2014

Abrir carpeta desde VBA

Función que abre una carpeta desde VBA. Llamando al shell de windows, lanzo la apertura de la carpeta.

Sub openFolder(folderName As String)
    retVal = Shell("explorer.exe " & folderName, vbNormalFocus)
End Sub


Comprobar si existe un archivo en VBA

Función para comprobar si existe o no un archivo. Como parámetro de entrada tengo la ruta del archivo y la función devuelve si existe o no.

Function fileExists(filename) As Boolean
   Dim fso, msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.fileExists(filename)) Then
      fileExists = True
      Exit Function
   Else
      fileExists = False
      Exit Function
   End If
End Function

viernes, agosto 22, 2014

Convertir fecha de formato mm/dd/yyyy a dd/mm/yyyy

Me pasaron un excel con fechas en formato inglés en modo texto. Así es cómo las he transformado en fecha en español. Soy consciente de que esta no es la forma mas elegante de hacer esto, pero tenía prisa...

Sub flipDate()
   i = 2
   While (Range("M" & i) <> "")
    
     If Len(Range("M" & i)) = 9 Then
        mm = Left(Range("M" & i), 1)
        dd = Mid(Range("M" & i), 3, 2)
        yyyy = Right(Range("M" & i), 5)
        
     Else
        mm = Left(Range("M" & i), 2)
        dd = Mid(Range("M" & i), 4, 2)
        yyyy = Right(Range("M" & i), 4)
        
     End If
    
     Range("M" & i).Value = ""
     Range("M" & i) = Format(Date, "dd/mm/yyyy")
     Range("M" & i).Value = dd & "/" & mm & "/" & yyyy
     
     
     'Range("M" & i).Activate
     
     DoEvents
     i = i + 1
     'Debug.Print i
     
     'Application.ScreenUpdating = False
   Wend
     Application.ScreenUpdating = True
     MsgBox ("Done!")
End Sub

jueves, mayo 30, 2013

Romper password de Workbook protegido con contraseña en Excel

Agregar un módulo con el siguiente código a el workbook que queramos ejecutar y nos mostrará la password.

'Muestra el password del Workbook a desproteger y lo desprotege
Sub passwordBreaker()

Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
   For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
      For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
         For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
         ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox "El password es " & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next

End Sub