Sub test()
Dim r%, i%
Dim arr, brr
Dim mypath$, myname$
mypath = ThisDocument.Path & ""
myname = "k1a.txt"
If Dir(mypath & myname) = "" Then
MsgBox mypath & myname & "不存在!"
Exit Sub
End If
Open mypath & myname For Input As #1
arr = Split(StrConv(InputB(LOF(2), 1), vbUnicode), vbCrLf)
Close #1
ReDim brr(0 To UBound(arr), 0 To 3)
For i = 0 To UBound(arr)
ss = Trim(arr(i))
crr = Split(ss, Chr(9))
For j = 0 To UBound(crr)
brr(i, j) = crr(j)
Next
Next
m = 2
n = 1
With ThisDocument
With .Tables(1)
For i = 0 To UBound(brr)
For j = 0 To UBound(brr, 2)
.Cell(m, n + j).Range.Text = brr(i, j)
Next
m = m + 2
If m > .Rows.Count Then
n = n + 4
m = 1
End If
If n > 5 Then
Exit Sub
End If
Next
End With
End With
End Sub
這個程式碼只能匯入一個表格,第二頁就不行,能否修改成以k1a.doc為範本,複製範本為k1b.doc並將資料匯入由左洏右表格,以資料多少決定多少表格.作者: fusahe 時間: 2018-10-3 21:48