
INSERTAR RENGLON EN LIBRO DE EXCEL EXISTENTE
Publicado por ISMAEL (2 intervenciones) el 18/05/2018 21:45:46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
' -------------------------------------------------------------------------------------------
' \\ -- función para psar los datos hacia una hoja de un libro exisitente
' -------------------------------------------------------------------------------------------
Public Function Exportar_Excel(sBookFileName As String) As Boolean
'End Function
On Error GoTo Error_Handler
Dim o_Excel As Object
Dim o_Libro As Object
Dim o_Hoja As Object
Dim Fila As Long
Dim Columna As Long
' -- Error en la ruta del libro
If sBookFileName = vbNullString Or Len(Dir(sBookFileName)) = 0 Then
Call Exportar_Excel1(sBookFileName)
MsgBox " Falta el Path del archivo de Excel o no se ha encontrado el libro en la ruta especificada ", vbCritical
Exit Function
End If
' -- Crea el objeto Excel, el objeto workBook y el objeto sheet
Set o_Excel = CreateObject("Excel.Application")
Set o_Libro = o_Excel.Workbooks.open(sBookFileName)
' -- Comprobar si se abre la hoja por defecto, o la indicada en el parámetro de la función
If Len(sNameSheet) = 0 Then
Set o_Hoja = o_Libro.Worksheets(1)
Else
Set o_Hoja = o_Libro.Worksheets(sNameSheet)
End If
' -- Bucle para Exportar los datos
'With FlexGrid
'For Fila = 1 To .Rows - 1
'For Columna = 0 To .Cols - 1
' o_Hoja.Cells(Fila, Columna + 1).Value = .TextMatrix(Fila, Columna)
'o_Hoja.Cells(1, 1).Value = "PESOS" '.TextMatrix(Fila, Columna)
'o_Hoja.Cells(1, 1).HorizontalAlignment = xlCenter
'o_Hoja.Cells(1, 2).Value = "UNIDADES"
'o_Hoja.Cells(1, 3).Value = "FECHA"
'o_Hoja.Cells(1, 4).Value = "HORA"
'o_Hoja.Cells.SpecialCells (Microsoft.Office.Interop.o_Excel.XlCellType.xlCellTypeLastCell)
o_Hoja.CELLS(2, 1).Value = TXTLECTURA.Text
o_Hoja.CELLS(2, 2).Value = TXTUNIDAD.Text
o_Hoja.CELLS(2, 3).Value = Date
o_Hoja.CELLS(2, 4).Value = Time
'o_Hoja.CELLS(2, 2).Select
'Selection.Insert Shift:=xlDown
'Next
'Next
'End With
' -- Cerrar libro y guardar los datos
o_Libro.Close True
' -- Cerrar Excel
o_Excel.Quit
' -- Terminar instancias
Call ReleaseObjects(o_Excel, o_Libro, o_Hoja)
Exportar_Excel = True
Exit Function
Error_Handler:
' -- Cierra la hoja y el la aplicación Excel
If Not o_Libro Is Nothing Then: o_Libro.Close False
If Not o_Excel Is Nothing Then: o_Excel.Quit
Call ReleaseObjects(o_Excel, o_Libro, o_Hoja)
If Err.Number <> 1004 Then MsgBox Err.Description, vbCritical
End Function
Valora esta pregunta


0