我编写了一个代码,用于在“.dat”文件中保存excel中的表,其中“.dat”文件的名称是表格的头部。
表格头下的信息应保存在与顶部对应的文件中。
例:
A1 B2 C3 B7
12 78 99 15
13 79 99 15
14 80 99 15
15 81 99 15
16 82 99 15
17 83 99 15
18 84 99 15
19 85 99 15
86 99 15
87 99
88 99
89 99
99
99
我将 A1.dat 的号码为12 13 14 15 16 17 18 19。
一切都好,但是当我选择全部时,在文件中我有空格和结尾,如下所示:
12
13
14
15
16
17
18
19
" "
" "
" "
" "
" "
" "
文件中没有“”,我写下来强调我的文件中有空格。我不希望文件中有这些空格。
以下是代码:
Sub salvaremodule2()
Dim a As Range
Dim b As Range
Dim i As Integer
Dim k As Integer
Dim j As Integer
Dim folderPath As String
Dim file As String
Dim TextFile As Integer
If Len(Dir(ThisWorkbook.Path & "\dat-uri\", vbDirectory)) = 0 Then MkDir ThisWorkbook.Path & "\dat-uri\"
End If
folderPath = ThisWorkbook.Path & "\dat-uri\"
Set a = Application.InputBox("Referintele:", Type:=8)
For i = 1 To a.Columns.Count
file = folderPath & (a(i) + ".dat") 'titlu
Open file For Output As #1
Close #1
file = folderPath & (a(i) + ".dat") 'incarcare module in fisiere
Open file For Output As #2
For j = 2 To a.Rows.Count
Print #2, a(j, i)
Next j
Close #2
Next i
End Sub
谢谢!