谢谢你的帮助。我已经想通了,并成功地提出了代码来执行我需要的东西。我还有一个问题,希望你能提供帮助。附上我的代码,注意加粗部分。我希望将 sourceSheet 作为工作表复制并粘贴到 targetSheet(“NewBook”的 Sheet2)中,但我希望将其粘贴为值。这是需要查看的特定部分......下面是完整的代码。
Set sourceBook = Application.Workbooks.Open(sourceFilename)
Set sourceSheet = sourceBook.Sheets("Current")
Set targetSheet = NewBook.Sheets("Sheet2")
sourceSheet.Copy targetSheet
Set targetSheet = NewBook.Sheets("Current")
targetSheet.Name = "Previous"
Sub Subtype()
Dim sourceBook As Workbook
Dim filter As String
Dim caption As String
Dim sourceFilename As String
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
If customerFilename = "False" Then
' GoTo Here:
End If
filter = "Text files (*.xlsx),*.xlsx"
caption = "Please Select an input file "
sourceFilename = Application.GetOpenFilename
Set NewBook = Workbooks.Add
With NewBook
.Title = "Subtype Practice"
End With
Set sourceBook = Application.Workbooks.Open(sourceFilename)
Set sourceSheet = sourceBook.Sheets("Current")
Set targetSheet = NewBook.Sheets("Sheet2")
sourceSheet.Copy targetSheet
Set targetSheet = NewBook.Sheets("Current")
targetSheet.Name = "Previous"
sourceBook.Close
Dim sourceBook1 As Workbook
Dim sourceFilename1 As String
Dim sourceSheet1 As Worksheet
Dim targetSheet1 As Worksheet
sourceFilename1 = Application.GetOpenFilename
Set sourceBook1 = Application.Workbooks.Open(sourceFilename1, Password:="BMTBD")
Set sourceSheet1 = sourceBook1.Sheets("Data")
Set targetSheet1 = NewBook.Sheets("Sheet1")
sourceSheet1.Copy targetSheet1
Set targetSheet1 = NewBook.Sheets("Data")
targetSheet1.Name = "Current"
Application.DisplayAlerts = False
Sheets("Sheet1").Delete
Application.DisplayAlerts = True
End Sub