martes, 15 de abril de 2014

CONVERTIR FECHA QUE NO SON RECONOCIDAS COMO 04-ENE-14 a 04/01/14




  Range("B1:B6000").Select
 


Dim cell As Range
For Each cell In Selection
If cell.Value <> "" And cell.Offset(0, 4).Value <> "" Then
'Dim u As String
'    u = ActiveCell.Value
    cell.Value = Format(cell, "MM/DD/YYYY")
End If
Next

miércoles, 25 de septiembre de 2013

CREAR INDICE DE HOJAS CON EL DATO QUE HAY EN LA CELDA C4 (DE CADA HOJA)


Sub Listado_Hojas()



'19-abr-11
Dim dato As Long
Dim rangoA1 As Range
Dim NuevoNombre, Resp
'Se validan archivos abiertos.
'
On Error GoTo Errores
Application.StatusBar = "Creando índice ..."
Application.ScreenUpdating = False
ActiveWorkbook.Sheets.Add Before:=Sheets(1)
Set rangoA1 = Sheets(1).Range("a1")
Sheets(1).Range("a1").Value = "ÍNDICE"
dato = ActiveWorkbook.Sheets.Count
Application.Calculation = xlCalculationManual
For i = 1 To dato
    With Sheets(1)
        .Hyperlinks.Add Anchor:=rangoA1.Offset(i, 0), Address:="", _
        SubAddress:="'" & Sheets(i).Name & "'" & "!A1", _
        TextToDisplay:="+'" & Sheets(i).Name & "'" & "!C4"
       

    End With
Next i
ActiveSheet.Range("A2").EntireRow.Delete
Application.ScreenUpdating = True
Application.StatusBar = False
Application.Calculation = xlCalculationAutomatic


Cells.Select
    ActiveWindow.DisplayGridlines = False
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight
    Range("B1").Select
    Columns("B:B").ColumnWidth = 36.29
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight2
        .TintAndShade = -0.249977111117893
        .PatternTintAndShade = 0
    End With
    With Selection.Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With


Resp = MsgBox("Desea asignarle un nombre la hoja de índice creada?", vbYesNoCancel + vbQuestion, AddIn)
If Resp = vbYes Then
Application.Dialogs(xlDialogWorkbookName).Show
Else
Exit Sub
End If
Exit Sub
Errores:
Application.Calculation = xlCalculationAutomatic


MsgBox "Ha ocurrido un error: " & vbNewLine & vbNewLine & Err.Description, vbExclamation, AddIn

End Sub

martes, 24 de septiembre de 2013

COMO NOMBRAR HOJAS (Cuando el nombre esta en una Celda de la misma hoja)

Dim w As Worksheet
For Each w In ThisWorkbook.Worksheets w.Name = w.Range("B8")
Next w
End Sub

luego vas a cada una de tus hojas y colocas lo siguiente

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$B$8" Then
ActiveSheet.Name = Range("B8")
End If
End Sub

Fuente:http://www.todoexpertos.com/categorias/tecnologia-e-internet/software-y-aplicaciones/microsoft-excel/respuestas/1936210/nombre-de-hoja-segun-datos-de-una-celda

miércoles, 22 de mayo de 2013

COMO DESCARGAR UN ARCHIVO A UNA CARPETA DESDE UNA URL DEFINIDA

Option Explicit Private Declare Function URLDownloadToFile Lib "urlmon" _ Alias "URLDownloadToFileA" (ByVal pCaller As Long, _ ByVal szURL As String, ByVal szFileName As String, _ ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long Dim Ret As Long Sub Sample() Dim strURL As String'almacena link Dim strPath As String'almacena direccion donde va a guardar strURL = "http://www.superfinanciera.gov.co/Cifras/informacion/diarios/tcrm/historia.xls" strPath = "D:\Mis documentos\Historico TRM\myfilename.xls"'importante al pegar la ruta debe poner el nombre del archivo como va quedar guardado junto con la extension Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)'realizar descarga If Ret = 0 Then MsgBox "File successfully downloaded" Else MsgBox "Unable to download the file" End If End Sub

jueves, 16 de febrero de 2012

CREAR ACCION MENU CONTEXTUAL (BOTON DERECHO)



Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call DeleteFromCellMenu

End Sub

Sub AddToCellMenu()
Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl

'**************esto se ejecuta si no hace la funcion de before close********************
'Eliminar los controles de primera para evitar duplicados.
'Llama a DeleteFromCellMenu
'**************esto se ejecuta si no hace la funcion de before close********************

'Establecer ContextMenu al menú contextual de la célda.
Set ContextMenu = Application.CommandBars("Cell")

'Añadir un botón integrado (guardar = 3) en el menú contextual de la célda.
ContextMenu.Controls.Add Type:=msoControlButton, ID:=3, before:=2

'Añadir un botón personalizado en el menú contextual de la célda.
With ContextMenu.Controls.Add(Type:=msoControlButton, before:=1)
.OnAction = "ChooseSheet" '''' asi se llama la macro va y busca la rutina
.FaceId = 516
.Caption = "Ubicación Hoja"
.Tag = "My_Cell_Control_Tag"
End With

End Sub

Sub DeleteFromCellMenu()
Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl

'Establecer ContextMenu al menú contextual de la célda.
Set ContextMenu = Application.CommandBars("Cell")

'Eliminar los controles personalizados con el tag: My_Cell_Control_Tag.
For Each ctrl In ContextMenu.Controls
If ctrl.Tag = "My_Cell_Control_Tag" Then
ctrl.Delete
End If
Next ctrl

'Eliminar la costumbre incorporada en el botón Guardar.
On Error Resume Next
ContextMenu.FindControl(ID:=3).Delete
On Error GoTo 0
End Sub



Private Sub Workbook_Open()
Call AddToCellMenu
End Sub

miércoles, 15 de febrero de 2012

IR A UNA HOJA POR MEDIO DE MENU


METODO 1

Sub Goanysheet()

myShtees = ActiveWorkbook.Sheets.Count
For i = 1 To myShtees
myList = myList & i & " - " & ActiveWorkbook.Sheets(i).Name & " " & vbCr
Next i
Dim mihojita As Single
mihojita = InputBox("Selecciones la hoja a la que desea ir." & vbCr & vbCr & myList)
Sheets( myShtees ).Select
End Sub


METODO 2 ******para mi el mejor******

Sub ChooseSheet()

Dim ws As Worksheet
Application.CommandBars("Workbook Tabs").ShowPopup

Set ws = ActiveSheet

End Sub