Hey everyone,
I'm using an ActiveX Button to trigger a macro which import a sheet of a workbook in my current workbook. Until here no problem, I'm using my GetOpenFilename method, set as a wb, open, move, etc..
But then come the close method! (na na na naaaa)
So it make this error, but, if I don't pay attention to it [On Error Resume Next & On Error Goto 0], everything work well!
I looked up in few similar thread, but even if I use this exact same code, the error still happen.
So here's my code :
Thanks you for taking time to help!
EDIT: I'm not using userform
I'm using an ActiveX Button to trigger a macro which import a sheet of a workbook in my current workbook. Until here no problem, I'm using my GetOpenFilename method, set as a wb, open, move, etc..
But then come the close method! (na na na naaaa)
Run-time error '-2147221080 (800401a8)':
Method 'Close' of object '_Workbook' failed
So it make this error, but, if I don't pay attention to it [On Error Resume Next & On Error Goto 0], everything work well!
I looked up in few similar thread, but even if I use this exact same code, the error still happen.
So here's my code :
Code:
'Import file
Dim ImportFile As String
ImportFile = Application.GetOpenFilename("Microsoft Excel Worksheet (*.xlsx),*.xslx")
'------DisplayAlert--Stop--&--ScreenUpdating--Stop--------
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'---------------To--make--it--smoother--------------------
'Check if Import file already exist in the current WB
Dim Sh As Worksheet
On Error Resume Next
Set Sh = Worksheets("Forecast")
On Error GoTo 0
If Not Sh Is Nothing Then
Sh.Delete
End If
'Open Import file
If ImportFile = "False" Then Exit Sub
Dim wb As Workbook
Set wb = Workbooks.Open(ImportFile, True)
Sheets.Select
ActiveSheet.Name = "Forecast"
Sheets.Move After:=Workbooks("Final Project.xlsm").Sheets(1)
'Close the workbooks of ImportFile
On Error Resume Next '[I don't know why, The Close method is working but trigger a error]
'[even with DisplayAlerts = False I must use On error to make it work..]
wb.Close savechanges:=False
On Error GoTo 0
Thanks you for taking time to help!
EDIT: I'm not using userform
Last edited: