我正在尝试将所有工作簿中名为“ Zeit&Kostenerfassung”的工作表复制到桌面文件中。该代码应打开它们(一个接一个)并复制所需的工作表。将其粘贴到当前工作簿中,并且还应该重命名工作表(Zeit&Kostenerfassung1; Zeit&Kostenerfassung2; ...),因为它们显然不能全都具有相同的名称。
将工作簿粘贴到桌面文件后,应再次关闭。
我尝试了下面的代码,很不幸,该代码无法正常工作。
任何帮助,我们将不胜感激!
Sub CopySheetFromFileOnDesktop()
Dim wkbDest As Workbook
Dim wksDest As Worksheet
Dim wkbSource As Workbook
Dim wksSource As Worksheet
Dim MyPath As String
Dim MyFile As String
Application.ScreenUpdating = False
Set wkbDest = ThisWorkbook
Set wksDest = wkbDest.Worksheets("Tabelle1")
MyPath = "C:\Users\..."
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "*.xlsx")
Do While Len(MyFile) > 0
Set wkbSource = Workbooks.Open(MyPath & MyFile)
Set wksSource = wkbSource.Worksheets("Zeit&Kostenerfassung")
Sheets("Zeit&Kostenerfassung").Copy
Before:=Workbooks("PullDataFromOutlook").Sheets(SheetIndex)
wkbSource.Close savechanges:=False
MyFile = Dir
Loop
Application.ScreenUpdating = True
MsgBox "Completed...", vbInformation
End Sub