Mostrando entradas con la etiqueta VBA. Mostrar todas las entradas
Mostrando entradas con la etiqueta VBA. Mostrar todas las entradas

martes, 10 de septiembre de 2013

Código que utilizo para tabular los esquemas.

Sub Tabular()
    Dim Tabs As Integer
    Tabs = 0
    QuitarIntrosDobles
    Selection.HomeKey Unit:=wdStory
    For i = 1 To 400
   
        Selection.MoveDown Unit:=wdParagraph, Count:=1
        If Selection.Text = "" Then
            Selection.Delete
        Else
            If Selection.Style = "Indices1" Then
                Tabs = 1
                Selection.Style = "Normal"
            Else
                If Selection.Style = "Indices2" Then
                    PonerTabs (1)
                    Tabs = 2
                    Selection.Style = "Normal"
                Else
                    If Selection.Style = "Indices3" Then
                        PonerTabs (2)
                        Tabs = 3
                        Selection.Style = "Normal"
                    Else 'Es normal
                        PonerTabs (Tabs)
                    End If
                End If
            End If
        End If
    Next
End Sub

Sub PonerTabs(cantidad As Integer)
    Selection.HomeKey Unit:=wdLine
    For j = 1 To cantidad
        Selection.TypeText Text:=vbTab
    Next j
End Sub

Sub QuitarIntrosDobles()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

domingo, 24 de octubre de 2010

Desordenar una columna de valores en Excel



  1. Sub Desordenar()
  2. Dim rango As Range
  3.  
  4. Set rango = Selection.Cells
  5. For i = 1 To rango.Rows.Count
  6. Dim aleatorio As Integer
  7. Dim cadena As String
  8. rango.Rows(i).Select
  9. cadena = ActiveCell.FormulaR1C1
  10. aleatorio = Int(Rnd() * rango.Rows.Count) + 1
  11. rango.Rows(i).FormulaR1C1 = rango.Rows_
    (aleatorio).FormulaR1C1
  12. rango.Cells(aleatorio).FormulaR1C1 = cadena
  13. Next
  14. End Sub

jueves, 4 de diciembre de 2008

VBA Excel: Brain Training


Sub InventarOperaciones()
    Dim i As Integer
    Dim NumOperaciones As Integer
    Dim operacion As String
    NumOperaciones = 10
    For i = 1 To NumOperaciones
        Cells(i, 1) = Int((Rnd * 10) + 1)
        operacion = Int((Rnd * 3) + 1)
        If operacion = "1" Then operacion = "+"
        If operacion = "2" Then operacion = "-"
        If operacion = "3" Then operacion = "*"
        Cells(i, 2) = operacion
        Cells(i, 3) = Int((Rnd * 10) + 1)
        Cells(i, 4) = ""
        Cells(i, 5) = ""
    Next
    Cells(1, 4).Select
End Sub

Sub ComprobarOperaciones()
    Dim i As Integer
    Dim NumOperaciones As Integer
    Dim operacion As String
    Dim resultado As Integer
    Dim puntos As Integer
    NumOperaciones = 10
    puntos = 0
    For i = 1 To NumOperaciones
        operacion = Cells(i, 2)
        If operacion = "+" Then resultado = Cells(i, 1) + Cells(i, 3)
        If operacion = "-" Then resultado = Cells(i, 1) - Cells(i, 3)
        If operacion = "*" Then resultado = Cells(i, 1) * Cells(i, 3)
        If Cells(i, 4) = resultado Then
            Cells(i, 5) = "OK"
            puntos = puntos + 1
        Else
            Cells(i, 5) = resultado
        End If
        
    Next
    MsgBox "PUNTOS:" & puntos
End Sub

martes, 2 de diciembre de 2008

Access VBA: Realizar una consulta por código


Private Sub tipo_AfterUpdate()
    Dim r As DAO.Recordset
    Dim db As DAO.Database
    Dim SQL As String
    Set db = CurrentDb
    SQL = "select * from servicios where codservicio=" & tipo
    Set r = db.OpenRecordset(SQL)
    descripcion = r(1)
    precio = r(2)
End Sub

jueves, 20 de noviembre de 2008

Excel VBA: Crear tablas de multiplicar


Sub Prueba()
    For i = 1 To 10
        For j = 1 To 10
            Range(Cells(i, j), Cells(i, j)).Select
            ActiveCell.FormulaR1C1 = i & "x" & j & "=" & i * j
        Next
    Next
End Sub