我在下面有这段代码,它将把一些数据从“sourceworkbook”导入到我的“currentworkbook”中。当我打开“当前工作簿”时,导入数据后,我无法移动包含“报告”文件或“源工作簿”文件的文件夹。
我可以做些什么来保持我的“当前工作簿”打开并且仍然能够手动(拖放)移动包含“报告”或“源工作簿”文件的文件夹?
似乎“sourceworkbook”仍然在 excel 中打开,因此我无法移动包含“sourceworkbook”的文件夹。但是,我想我在我的代码行中关闭了“sourceworkbook”?
Sub RES_Import()
Filename = Application.GetOpenFilename()
Application.ScreenUpdating = False 'Reduce screen flickering
Application.DisplayAlerts = False 'Remove "Delete Sheet" Warning
If Filename = False Then
MsgBox "No file Selected."
Else
Dim sourceworkbook As Variant
Dim currentworkbook As Workbook
Dim test As String
Dim sht As Worksheet
Set currentworkbook = ThisWorkbook
Set sourceworkbook = Workbooks.Open(Filename)
For Each sht In currentworkbook.Worksheets
If sht.Name = "report" Then
currentworkbook.Worksheets("report").Delete
sourceworkbook.Sheets(1).Copy before:=currentworkbook.Sheets(1)
sourceworkbook.Close SaveChanges:=False
Exit For
Else
sourceworkbook.Sheets(1).Copy before:=currentworkbook.Sheets(1)
sourceworkbook.Close False
Exit For
End If
Next sht
End If
Application.DisplayAlerts = True 'Enable "Delete Sheet" Warning
Set sourceworkbook = Nothing
Set currentworkbook = Nothing
ThisWorkbook.Activate
Application.ScreenUpdating = True 'Reduce screen flickering
End Sub