Hello,
This is the macro (also partly with your help) where I select a sheet and import it into a workbook. When cells are not the same the sheet is not imported else the sheet is imported. But I also want a message when the macrobutton is hit and the sheet doesn't exist in c:\temp and the macro is ended. I've tried "On error goto..:" and a msgbox file not found but then when the file exists I still get the msgbox.
This is the macro (also partly with your help) where I select a sheet and import it into a workbook. When cells are not the same the sheet is not imported else the sheet is imported. But I also want a message when the macrobutton is hit and the sheet doesn't exist in c:\temp and the macro is ended. I've tried "On error goto..:" and a msgbox file not found but then when the file exists I still get the msgbox.
Code:
Workbooks.Open Filename:="c:\temp\Test1.xls"
If Sheets("Test 1").[G1] <> Workbooks("Book1").Sheets("Test2").[G5] Then
MsgBox "Wrong sheet!"
Windows("Test1.xls").Activate
ActiveWindow.Close saveChanges:=False
Else
Application.DisplayAlerts = False
Sheets("test 1").Copy Before:=Workbooks("Book1"). _
Sheets(1)
Windows("Test1.xls").Activate
ActiveWindow.Close saveChanges:=False
Sheets("Test 1").Select
Range("A4").Select
End If
End Sub