我是VBA初學者,需要請教各位VBA前輩們
指令碼如下,而我希望能夠將'D:\test\ i \[test.xlsx]工作表1'的i是變數,加入於迴圈之中
但執行結果不如預期,路徑無法變成變數
Sub 巨集1()
Dim i
For i = 1 To 2 Step 1
Range("a" & i & ":d" & i).Formula = "='D:\test\ i \[test.xlsx]工作表1'!A1:D1"
Range("a" & i & ":d" & i).Formula = Range("a" & i & ":d" & i).Value
Sub test()
FPath = "D:\test\i\test.xlsx"
With Workbooks.Open(FPath)
'您的主程式需求,因為您的寫法有問題
'所以無法得知您實際的需求
.Close
End With
End Sub作者: x7776658 時間: 2021-11-12 09:47
Sub test()
For i = 1 To 2
FPath = "D:\test\" & i & "\test.xlsx"
With Workbooks.Open(FPath)
Arr = Range("a1:d1")
.Close
End With
Range("a" & i).Resize(, 4) = Arr
Next
End Sub作者: x7776658 時間: 2021-11-12 13:14