Datos de 2 TXT a XLS
Hola:
Necesito terminar lo siguiente:
Estoy haciendo una macro que me inserta en cada hoja de Excel dependiendo del primer string del txt. Esto lo hace perfecto.
Lo que trato de hacer ahora es tener otro TXT con la posición inicial de CADA hoja.
En mi macro leo los 2 TXT y al comparar los 2 nombres de las hojas se me genera mi confusión. Tengo esto: If parametros(0) = nomhoja Then , PERO en vez de "nomhoja", debe ser el string 'sHoja' que contiene todas los nombre de las hojas del PRIMER TXT
parametros.txt
Prioritarios GENERAL LENG (tecla tab) C5
GENERAL LENG (tecla tab) F7
__
En el método LlenaLinea están los for que recorren las 2 matrices que contienen los datos
macro:
Dim sUltimaHoja As String
Dim CntFilas As Integer
Sub Llenar()
Set fso = CreateObject("Scripting.FileSystemObject")
Dim sRuta As String
Dim sLinea As String
Dim sHoja() As String
sRuta = ActiveWorkbook.Path
Set archivo = fso.OpenTextFile(sRuta + "/datostab.txt", 1)
Do While Not archivo.AtEndOfStream
sLinea = archivo.readline()
sHoja = Split(sLinea, vbTab)
If UCase(sUltimaHoja) <> UCase(sHoja(0)) Then
If Trim(sUltimaHoja) <> "" Then
'For i = 1 To 8
'Suma CntFilas + 1, i, 2
'Next
End If
sUltimaHoja = sHoja(0)
CntFilas = 0
Else
CntFilas = 0 + 1
End If
If Not SheetExist(sUltimaHoja) Then
Sheets.Add
ActiveSheet.Name = sUltimaHoja
End If
'txt parametros
Set fso1 = CreateObject("Scripting.FileSystemObject")
Dim sRutaP As String
Dim sLineaParametros As String
Dim sHojaParam() As String
sRutaP = ActiveWorkbook.Path
Set archivoparam = fso1.OpenTextFile(sRutaP + "/parametros.txt", 1)
Do While Not archivoparam.AtEndOfStream
sLineaParametros = archivoparam.readline()
sHojaParam = Split(sLineaParametros, vbTab)
If UCase(sUltimaHojaP) <> UCase(sHojaParam(0)) Then
If Trim(sUltimaHoja) <> "" Then
'nn
End If
sUltimaHojaP = sHojaParam(0)
'CntFilas = 0
Else
'CntFilas = 0 + 1
End If
'lee sLineaParametros, sUltimaHojaP
Loop
' archivoparam.Close
LlenaLinea sUltimaHoja, sLinea, CntFilas, sLineaParametros, sUltimaHojaP
Loop
'Para la última hoja
'For i = 1 To 8
'Suma CntFilas + 1, i, 2
'Next
Archivo.Close
archivoparam.Close
'MsgBox "Importado"
End Sub
Sub LlenaLinea(ByVal sHoja As String, ByVal sLinea As String, ByVal nFila As Double, ByVal sLineaParametros As String, ByVal nomhoja As String)
Dim columna As Double
Dim ifila As Integer
columna = 0
Sheets(sHoja).Select
parametros = Split(sLineaParametros, vbTab)
b = Split(sLinea, vbTab)
'MsgBox (parametros(0))
If parametros(0) = nomhoja Then
For i = 1 To UBound(parametros)
columnaletra = Mid(parametros(1), 1, 1)
columna = LetraANumero(columnaletra)
ifila = Mid(parametros(1), 2, 1)
For j = 1 To UBound(b)
If (IsNumeric(b(j))) Then
Dim totColumna As Integer
totColumna = columna + j
Cells(nFila + ifila, columna + j) = CDbl(b(j))
Cells(nFila + ifila, columna + j).Interior.ColorIndex = 6
Else
Cells(nFila + ifila, columna + j) = b(j)
Cells(nFila + ifila, columna + j).Interior.ColorIndex = 6
End If
'Para diseñar celdas
Dim vaColumna As Integer
vaColumna = columna + j
Dim vaFila As Integer
vaFila = nFila + ifila
Range(Cells(vaFila, vaColumna), Cells(vaFila, vaColumna)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
...
Necesito terminar lo siguiente:
Estoy haciendo una macro que me inserta en cada hoja de Excel dependiendo del primer string del txt. Esto lo hace perfecto.
Lo que trato de hacer ahora es tener otro TXT con la posición inicial de CADA hoja.
En mi macro leo los 2 TXT y al comparar los 2 nombres de las hojas se me genera mi confusión. Tengo esto: If parametros(0) = nomhoja Then , PERO en vez de "nomhoja", debe ser el string 'sHoja' que contiene todas los nombre de las hojas del PRIMER TXT
parametros.txt
Prioritarios GENERAL LENG (tecla tab) C5
GENERAL LENG (tecla tab) F7
__
En el método LlenaLinea están los for que recorren las 2 matrices que contienen los datos
macro:
Dim sUltimaHoja As String
Dim CntFilas As Integer
Sub Llenar()
Set fso = CreateObject("Scripting.FileSystemObject")
Dim sRuta As String
Dim sLinea As String
Dim sHoja() As String
sRuta = ActiveWorkbook.Path
Set archivo = fso.OpenTextFile(sRuta + "/datostab.txt", 1)
Do While Not archivo.AtEndOfStream
sLinea = archivo.readline()
sHoja = Split(sLinea, vbTab)
If UCase(sUltimaHoja) <> UCase(sHoja(0)) Then
If Trim(sUltimaHoja) <> "" Then
'For i = 1 To 8
'Suma CntFilas + 1, i, 2
'Next
End If
sUltimaHoja = sHoja(0)
CntFilas = 0
Else
CntFilas = 0 + 1
End If
If Not SheetExist(sUltimaHoja) Then
Sheets.Add
ActiveSheet.Name = sUltimaHoja
End If
'txt parametros
Set fso1 = CreateObject("Scripting.FileSystemObject")
Dim sRutaP As String
Dim sLineaParametros As String
Dim sHojaParam() As String
sRutaP = ActiveWorkbook.Path
Set archivoparam = fso1.OpenTextFile(sRutaP + "/parametros.txt", 1)
Do While Not archivoparam.AtEndOfStream
sLineaParametros = archivoparam.readline()
sHojaParam = Split(sLineaParametros, vbTab)
If UCase(sUltimaHojaP) <> UCase(sHojaParam(0)) Then
If Trim(sUltimaHoja) <> "" Then
'nn
End If
sUltimaHojaP = sHojaParam(0)
'CntFilas = 0
Else
'CntFilas = 0 + 1
End If
'lee sLineaParametros, sUltimaHojaP
Loop
' archivoparam.Close
LlenaLinea sUltimaHoja, sLinea, CntFilas, sLineaParametros, sUltimaHojaP
Loop
'Para la última hoja
'For i = 1 To 8
'Suma CntFilas + 1, i, 2
'Next
Archivo.Close
archivoparam.Close
'MsgBox "Importado"
End Sub
Sub LlenaLinea(ByVal sHoja As String, ByVal sLinea As String, ByVal nFila As Double, ByVal sLineaParametros As String, ByVal nomhoja As String)
Dim columna As Double
Dim ifila As Integer
columna = 0
Sheets(sHoja).Select
parametros = Split(sLineaParametros, vbTab)
b = Split(sLinea, vbTab)
'MsgBox (parametros(0))
If parametros(0) = nomhoja Then
For i = 1 To UBound(parametros)
columnaletra = Mid(parametros(1), 1, 1)
columna = LetraANumero(columnaletra)
ifila = Mid(parametros(1), 2, 1)
For j = 1 To UBound(b)
If (IsNumeric(b(j))) Then
Dim totColumna As Integer
totColumna = columna + j
Cells(nFila + ifila, columna + j) = CDbl(b(j))
Cells(nFila + ifila, columna + j).Interior.ColorIndex = 6
Else
Cells(nFila + ifila, columna + j) = b(j)
Cells(nFila + ifila, columna + j).Interior.ColorIndex = 6
End If
'Para diseñar celdas
Dim vaColumna As Integer
vaColumna = columna + j
Dim vaFila As Integer
vaFila = nFila + ifila
Range(Cells(vaFila, vaColumna), Cells(vaFila, vaColumna)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
...
1 Respuesta
Respuesta de Isaac Reyes
1