這是我目前的代碼。騎行通過不同的範圍複製while循環
Sub Loops()
Dim MyPath As String
Dim MyFileName As String
Dim output As Variant
Dim outputRange(1 To 3) As Range
Set outputRange(1) = Worksheets("vbaTest").Range("output1", Worksheets("vbaTest").Range("output1").End(xlDown))
Set outputRange(2) = Worksheets("vbaTest").Range("output2", Worksheets("vbaTest").Range("output2").End(xlDown))
Set outputRange(3) = Worksheets("vbaTest").Range("output3", Worksheets("vbaTest").Range("output3").End(xlDown))
For Each output In outputRange
'The path and file names:
MyPath = "C:\Users\x\Custom Office Templates"
MyFileName = "Test"
'Makes sure the path name ends with "\":
If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
'Makes sure the filename ends with ".csv"
If Not Right(MyFileName, 4) = ".txt" Then MyFileName = MyFileName & ".txt"
'Copies the sheet to a new workbook:
Sheets("vbaTest").Range("**output1**").Copy
'The new workbook becomes Activeworkbook:
Workbooks.Add
ActiveSheet.Columns("A").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With ActiveWorkbook
Application.DisplayAlerts = False
End With
'Brings back original sheet
Workbooks("vbaTest.csv").Activate
'Starts at the top of code
Next output
End Sub
我無法循環顯示output1中設置的不同範圍。 「表格(」vbaTest「)。範圍(」output1「)。複製」
我試圖讓vba循環通過我設置的三個其他輸出。有什麼建議麼?
你想要的那部分更改爲不同的輸出響了起來。 ES,對嗎? 'Sheets(「vbaTest」)。Range(output.address).Copy'是否工作? – BruceWayne
是的。它只是工作。我昨天創辦了VBA,並且一直堅持在這一點上幾個小時。 非常感謝! – MRI
只是使用'output.Copy',因爲輸出是_already_一個'範圍'(儘管通過'Variant' _lens_) – user3598756