我想浏览一个文件夹并读取第一个excel文件,然后将数据复制到S列中,然后将其粘贴到另一个工作簿中,然后读取第二个文件并在上一个粘贴的最后一行之后粘贴值,依此类推
我的代码是
'''
Public MyFolder As String
Public MyFile As String
Public eRow As Long
Dim xl As New Excel.Application
With xl.FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show()
MyFolder = .SelectedItems(1) & "\"
Err.Clear()
End With
MyFile = Dir(MyFolder & "\*.xls*", FileAttribute.ReadOnly)
Dim BBSVal As String
Dim Lastrow As Long
BBSVal = cboBBS.Text
Do While Len(MyFile) > 0
xl.Workbooks.Open(Filename:=MyFolder & "\" & MyFile, UpdateLinks:=False)
Lastrow = xl.ActiveSheet.UsedRange.Rows.Count
Select Case BBSVal
Case Is = "S"
xl.ActiveSheet.Range("S1", "S" & Lastrow).Copy()
Case Else
End Select
xl.ActiveWorkbook.Close()
eRow = xl.Worksheets("BBSName").Cells(xl.Rows.Count, 1).End(Excel.XlDirection.xlUp).Offset(1,
0).Row
xl.ActiveSheet.Paste = xl.Worksheets("BBSName").Range((eRow, 1), (eRow, 1))
MyFile = Dir()
Loop
'''
代码运行没有错误,但是在指定的文件中粘贴未完成????非常感谢您的帮助
谢谢,问候Moheb Labib
S