標題:
[發問]
請教如何將選擇檔案(原本只能選一個,想改成一次選多個)
[打印本頁]
作者:
leoman0002
時間:
2013-5-16 20:54
標題:
請教如何將選擇檔案(原本只能選一個,想改成一次選多個)
原先是使用
fd = ThisWorkbook.Path & "\"
fs = Dir(fd & "*.csv")
但是常常有需要臨時匯入的情況,後來修改之後...變成一次只能匯入一個檔案,
想情教各位老師!! 我應該要修改哪裡 ^^
[attach]14995[/attach]
Sub ex()
Dim arr()
Dim Filename As Variant
Dim i As Integer
fs = Application.GetOpenFilename("僅能匯入csv格式,*.csv", , "確定", , False)
p = Range("G65536").End(xlUp).Row + 1
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", fs, False
.Send
tt = .responsetext
ss = Split(tt, vbCrLf)
End With
ReDim arr(0 To UBound(ss), 0 To 15)
For i = 0 To UBound(ss)
s1 = Split(ss(i), ",")
For j = 0 To UBound(s1)
arr(i, j) = s1(j)
Next j
Next i
Cells(p, "a") = Replace(arr(5, 1), "'", "")
Cells(p, "b") = Replace(Split(Cells(p, "a"), "-")(0), Mid(Split(Cells(p, "a"), "-")(0), 3, 5), "")
Cells(p, "c") = Split(Cells(p, "a"), "-")(1)
Cells(p, "G") = arr(3, 3)
If arr(11, 7) = "Bef" Then
Cells(p, "H") = "[Before]"
Else
Cells(p, "H") = "[After]"
End If
Cells(p, "I") = arr(11, 5)
Cells(p, "J") = arr(11, 5)
Cells(p, "K") = arr(20, 5)
Cells(p, "R") = arr(21, 5)
Cells(p, "S") = arr(22, 5)
Cells(p, "T") = arr(23, 5)
k = 20
For i = 26 To 33
For j = 1 To 3
k = k + 1
Cells(p, k) = arr(i, (j - 1) * 2 + 1)
Next j
Next i
End Sub
複製代碼
作者:
Hsieh
時間:
2013-5-16 22:17
回復
1#
leoman0002
Sub ex()
Dim arr()
Dim Filename As Variant
Dim i As Integer
fs = Application.GetOpenFilename("僅能匯入csv格式,*.csv", , "③確定", , True) '改成複選檔案
For Each f In fs '每個檔案迴圈
p = Range("G65536").End(xlUp).Row + 1
With CreateObject("Microsoft.XMLHTTP")
.Open "GET", f, False
.Send
tt = .responsetext
ss = Split(tt, vbCrLf)
End With
ReDim arr(0 To UBound(ss), 0 To 15)
For i = 0 To UBound(ss)
s1 = Split(ss(i), ",")
For j = 0 To UBound(s1)
arr(i, j) = s1(j)
Next j
Next i
Cells(p, "a") = Replace(arr(5, 1), "'", "")
Cells(p, "b") = Replace(Split(Cells(p, "a"), "-")(0), Mid(Split(Cells(p, "a"), "-")(0), 3, 5), "")
Cells(p, "c") = Split(Cells(p, "a"), "-")(1)
Cells(p, "G") = arr(3, 3)
If arr(11, 7) = "Bef" Then
Cells(p, "H") = "[Before]"
Else
Cells(p, "H") = "[After]"
End If
Cells(p, "I") = arr(11, 5)
Cells(p, "J") = arr(11, 5)
Cells(p, "K") = arr(20, 5)
Cells(p, "R") = arr(21, 5)
Cells(p, "S") = arr(22, 5)
Cells(p, "T") = arr(23, 5)
k = 20
For i = 26 To 33
For j = 1 To 3
k = k + 1
Cells(p, k) = arr(i, (j - 1) * 2 + 1)
Next j
Next i
Next f
End Sub
複製代碼
作者:
leoman0002
時間:
2013-5-17 00:08
這就是我想要的結果,學習到了....感謝
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)