Я создаю текстовый файл из электронной таблицы Excel с помощью следующего макроса Excel
Option Explicit
Public Sub WriteToTextFile()
Dim ws As Worksheet
Set ws = ActiveSheet 'better by its name: ThisWorkbook.Worksheets("Sheet1")
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Dim LastCol As Long
LastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
Open "C:\Users\Admin\Desktop\123.txt" For Output As #1
Dim iRow As Long
For iRow = 2 To LastRow
Dim OutputLine As String
Dim iCol As Long
For iCol = 1 To LastCol
If iCol = 1 Then 'first column (is different)
OutputLine = ws.Cells(iRow, iCol).Text
Else 'append other columns
OutputLine = OutputLine & "," & ws.Cells(1, iCol).Text & ": " & ws.Cells(iRow, iCol).Text
End If
Next iCol
'Debug.Print OutputLine
Print #1, OutputLine 'output the full line to the text file
Next iRow
Close #1
Shell "notepad.exe ""C:\Users\Admin\Desktop\123.txt""", vbNormalFocus
End Sub
Образцы данных электронной таблицы Excel представлены следующим образом
ID1 | ID2 |ID3
97 | 12 | 47
08 | 09 | 54
17 | 46 | 07
Myокончательный вывод -
97,ID2: 12,ID3: 47
08,ID2: 09,ID3: 54
17,ID2: 46,ID3: 07
При моем окончательном выводе я не могу получить данные строк (заголовки; см. пример ниже).Кто-нибудь может мне помочь с этим?
ID1,ID2,ID3
97,ID2: 12,ID3: 47
08,ID2: 09,ID3: 54
17,ID2: 46,ID3: 07
Заранее спасибо!