0
我有以下這段代碼的問題從多個文件粘貼。 當我打開excel時,它不會運行。Excel的VBA,
和
它不會從我的文件正確粘貼。我希望它進入最後一行並粘貼我的信息,然後從第二個文件中退出並粘貼,等等。
有什麼想法?
Private Sub Workbook_Open()
Dim FolderPath As String
Dim FileName As String
FolderPath = "D:\excelprojekt\"
FileName = Dir(FolderPath & "*.xlsx")
Dim lastrow As Long
Dim lastcolumn As Long
Do While FileName <> ""
Workbooks.Open (FolderPath & FileName)
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(1, 1), Cells(lastrow, lastcolumn)).Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
ActiveCell.Offset(rowOffset:=2, columnOffset:=0).Activate
ActiveSheet.PasteSpecial
End With
FileName = Dir
Loop
End Sub
你可能會在這裏找到至少一個答案:http://stackoverflow.com/questions/11369762/workbook-open-sub-wont-run-when-i-open-the-workbook – Ralph