You are on page 1of 9

Dim rutaArchivo As String Dim nombreArchivo As String Dim nombreArchivoActual As String Dim ValorAccion(200) As String Dim PrecioAccion(200) As Double

Dim nroValores As Integer Dim fecha As Date

Sub AbrirRuta()

Application.ScreenUpdating = False Application.Calculation = xlCalculationManual

'Ruta de Vector Acciones (Se puede eliminar en caso de cambios de Ruta o error) ChDrive "Z" ChDir "Z:\Riesgos de Mercado\3Inversiones\Operaciones de Reporte\Vector Acciones"

'Abrir Ventana de Dilogo para Seleccin del Archivo ruta = Application.GetOpenFilename("Archivos Excel (*.xls; *.xlsx), *.xls; *.xlsx", 1, "Seleccionar Archivo", , False)

If ruta = False Then Exit Sub Else 'Seleccionar los Archivo y Almcanenar los Nombres de Archivos en Celdas Range("E8", "G8").Value = ""

rutaArchivo = ruta nombreArchivo = Mid$(ruta, InStrRev(ruta, "\") + 1) Range("E8").Value = nombreArchivo 'Almacenar Ruta de Archivos en la Celda Respectiva Range("F8").Value = Mid$(ruta, 1, InStrRev(ruta, "\")) Range("I15").Select End If

'Activa la Actualizacin de Pantalla Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True

End Sub

Sub ActualizarTablas()

'Cambia el Estado a ESPERE Range("H15").Value = "ESPERE" Range("H15").Interior.ColorIndex = 3

Application.ScreenUpdating = False Application.Calculation = xlCalculationManual

nombreArchivoActual = ThisWorkbook.Name Windows("" & nombreArchivoActual & "").Activate Sheets("Valorizacin").Select

fecha = Cells(4, 5).Value rutaArchivo = Range("F8") & Range("E8")

Sheets("Vector").Select For i = 3 To [A1].End(xlToRight).Column If fecha = Cells(1, i) Then MsgBox ("Da indicado ya se encuentra en la base") 'Activa la Actualizacin de Pantalla Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic Exit Sub End If Next i

'Obtener Valores a Buscar Sheets("Vector").Select nroValores = [A1].End(xlDown).Row - 1 For i = 1 To nroValores ValorAccion(i) = Cells(i + 1, 1).Value Next i

'Abrir Libro With Workbooks.Open(rutaArchivo)

'Actualizar Datos de Tablas

.RefreshAll .Sheets("Hoja1").Select

Dim val As Integer val = 0 For i = 2 To [A1].End(xlDown).Row If Cells(i, 1) = fecha Then val = 1 End If Next i

If val = 1 Then

'Obtener Posicin de ltima Celda filafin = [A1].End(xlDown).Row

For i = 1 To nroValores For j = 2 To filafin If ValorAccion(i) = Cells(j, 2).Value And fecha = Cells(j, 1) Then PrecioAccion(i) = Cells(j, 6).Value End If Next j Next i

'Cerrar y Guardar Cambios .Close True

Else

'Activa la Actualizacin de Pantalla Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic

'Cambia el Estado a LISTO Range("H15").Value = "LISTO" Range("H15").Interior.ColorIndex = 2

MsgBox ("No existe informacin en lo descargado de la SMV para el da indicado")

Windows("" & nombreArchivoActual & "").Activate Sheets("Valorizacin").Select

.Close True Exit Sub

End If

End With

'Ir a Libro Destino Windows("" & nombreArchivoActual & "").Activate Sheets("Vector").Select

'Llenar datos colIng = [A1].End(xlToRight).Column + 1 Cells(1, colIng).Value = fecha For i = 1 To nroValores If PrecioAccion(i) = 0 Then Cells(i + 1, colIng).Value = Cells(i + 1, colIng - 1).Value Else Cells(i + 1, colIng).Value = PrecioAccion(i) End If Next i

'Dar formato de Celdas Columns(colIng - 1).Select Selection.Copy Columns(colIng).Select Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False Cells(1, 1).Select

'Activar Libro Destino Windows("" & nombreArchivoActual & "").Activate Sheets("Valorizacin").Select

'Activa la Actualizacin de Pantalla Application.ScreenUpdating = True

Application.Calculation = xlCalculationAutomatic

'Cambia el Estado a LISTO Range("H15").Value = "LISTO" Range("H15").Interior.ColorIndex = 2

End Sub

Sub ForzarDia()

'Cambia el Estado a ESPERE Range("H15").Value = "ESPERE" Range("H15").Interior.ColorIndex = 3

fecha = Cells(4, 5).Value

Application.ScreenUpdating = False Application.Calculation = xlCalculationManual

nombreArchivoActual = ThisWorkbook.Name Windows("" & nombreArchivoActual & "").Activate Sheets("Vector").Select

'Obtener Nro de Columna a Ingresar colIng = [A1].End(xlToRight).Column + 1

'Copiar Valores Columns(colIng - 1).Select Selection.Copy Columns(colIng).Select ActiveSheet.Paste Application.CutCopyMode = False Cells(1, 1).Select

'Pegar Fecha Cells(1, colIng).Value = fecha

'Activar Libro Destino Windows("" & nombreArchivoActual & "").Activate Sheets("Valorizacin").Select

'Activa la Actualizacin de Pantalla Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic

'Cambia el Estado a LISTO Range("H15").Value = "LISTO" Range("H15").Interior.ColorIndex = 2

End Sub

Function NOMBREDIA(X As Integer)

Select Case X Case 1 NOMBREDIA = "Lunes" Case 2 NOMBREDIA = "Martes" Case 3 NOMBREDIA = "Mircoles" Case 4 NOMBREDIA = "Jueves" Case 5 NOMBREDIA = "Viernes" Case 6 NOMBREDIA = "Sbado" Case 7 NOMBREDIA = "Domingo" End Select End Function

You might also like