使用InStr为.txt文件进行VBA循环

时间:2018-05-11 13:56:08

标签: excel-vba import vba excel

我在尝试从.txt file导入信息时遇到问题。我在文件中有这些数据:

EMPRESA : TRANSENER S.A.                
---- NODO --------------------         INYECCION
Descripción                     VNom       (MW)
ALICURA     500        2         500      251.8
---- LINEAS ------------------         PARTIC  CHPOTik  REMUNERACION
Descripción                     VNom      (%)    ($/H)  MENSUAL  ($)
ACABRAL-R.OESTE 500.0            500     0.15     5.24       3775.62
ALMAFUE.-ACABRAL 500.0           500     0.15     1.85       1335.12
------------------------------
---- NODO --------------------         INYECCION
Descripción                     VNom       (MW)
SANTO TOME  500  2               500      101.2
---- LINEAS ------------------         PARTIC  CHPOTik  REMUNERACION
Descripción                     VNom      (%)    ($/H)  MENSUAL  ($)
ALMAFUE.-EMBALSE-500-1           500     0.15     0.25        179.54
CHACO500-RESISTEN 500.0          500     0.10     0.17        124.02
------------------------------
---- NODO --------------------         INYECCION
Descripción                     VNom       (MW)
ALMAFUERTE    1.0     3            1       -9.5
---- LINEAS ------------------         PARTIC  CHPOTik  REMUNERACION
Descripción                     VNom      (%)    ($/H)  MENSUAL  ($)
ALMAFUE.-EMBALSE-500-1           500     0.15     0.25        179.54
CHACO500-RESISTEN 500.0          500     0.10     0.17        124.02

我想提取任何BUS(NODO)的信息:

Name                             Vnom    ( MW ) 
ALICURA     500        2         500      251.8 
SANTO TOME  500  2               500      101.2
ALMAFUERTE    1.0     3            1       -9.5

我制作此代码,但仅适用于第一个:

Private Sub BarrasIny_Click()
    Dim myFile As String
    Dim text As String
    Dim quote As String
    Dim textline As String

    myFile = "C:\Users\tvelis\Desktop\CFCT_por_barra2.txt"

    Open myFile For Input As #1
        Do Until EOF(1)
            Line Input #1, textline
            text = text & textline
        Loop
    Close #1

    quote = InStr(text, "---- NODO")
    Range("A1").Value = "Barra"
    Range("B1").Value = "Tension"
    Range("c1").Value = "MW"

    Range("A2").Value = Mid(text, quote + 103, 30)
    Range("B2").Value = Mid(text, quote + 136, 3)
    Range("C2").Value = Mid(text, quote + 145, 5)
End Sub

如何制作循环并从任何总线(NODO)中提取信息?

0 个答案:

没有答案