返回列表 上一主題 發帖

[發問] 請教如何將選擇檔案(原本只能選一個,想改成一次選多個)

回復 1# leoman0002
  1. Sub ex()
  2.    Dim arr()
  3.   Dim Filename As Variant
  4.   Dim i As Integer
  5.   fs = Application.GetOpenFilename("僅能匯入csv格式,*.csv", , "③確定", , True)  '改成複選檔案
  6.   For Each f In fs '每個檔案迴圈
  7.   p = Range("G65536").End(xlUp).Row + 1
  8.   With CreateObject("Microsoft.XMLHTTP")
  9.   .Open "GET", f, False
  10.   .Send
  11.   tt = .responsetext
  12.   ss = Split(tt, vbCrLf)
  13.   End With
  14.   ReDim arr(0 To UBound(ss), 0 To 15)
  15.   For i = 0 To UBound(ss)
  16.   s1 = Split(ss(i), ",")
  17.   For j = 0 To UBound(s1)
  18.     arr(i, j) = s1(j)
  19.   Next j
  20.   Next i
  21.   Cells(p, "a") = Replace(arr(5, 1), "'", "")
  22.   Cells(p, "b") = Replace(Split(Cells(p, "a"), "-")(0), Mid(Split(Cells(p, "a"), "-")(0), 3, 5), "")
  23.   Cells(p, "c") = Split(Cells(p, "a"), "-")(1)
  24.   Cells(p, "G") = arr(3, 3)
  25.   If arr(11, 7) = "Bef" Then
  26.   Cells(p, "H") = "[Before]"
  27.   Else
  28.   Cells(p, "H") = "[After]"
  29.   End If
  30.   Cells(p, "I") = arr(11, 5)
  31.   Cells(p, "J") = arr(11, 5)
  32.   Cells(p, "K") = arr(20, 5)
  33.   Cells(p, "R") = arr(21, 5)
  34.   Cells(p, "S") = arr(22, 5)
  35.   Cells(p, "T") = arr(23, 5)
  36.   k = 20
  37.   For i = 26 To 33
  38.   For j = 1 To 3
  39.     k = k + 1
  40.     Cells(p, k) = arr(i, (j - 1) * 2 + 1)
  41.   Next j
  42.   Next i
  43.   Next f
  44. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 能幹不幹,不如苦幹實幹。
返回列表 上一主題