maghari
06-16-2020, 01:38 PM
hello
this is my code doesn't work very well i no know it works until this line
1 MsgBox "name of the file is not correct", vbCritical
i'm sure about the name of opened file it supposes open the file and copy data but the code open the file but not copy data because show the message
i hope some body help
Sub Test()
Dim file_name As Variant
Dim open_wk As Workbook
On Error GoTo 1
file_name = Application.GetOpenFilename(Title:="choose the file ", FileFilter:="Excel Files *.xlsx (*.xlsx),")
If file_name = False Then1 MsgBox "name of the file is not correct", vbCritical
Exit Sub
Else
Set open_wk = Workbooks.Open(file_name)
EndIf
Windows("TT1.xlsx").Activate
Sheets("sheet1").Select
Range("a2:E15").Select
Selection.CopyThisWorkbook.Activate
Sheets("sheet1").Select
Range("b2").Select
Selection.PasteSpecial Paste:=xlPasteValues
ThisWorkbook.Close
Application.CutCopyMode = False
End Sub
this is my code doesn't work very well i no know it works until this line
1 MsgBox "name of the file is not correct", vbCritical
i'm sure about the name of opened file it supposes open the file and copy data but the code open the file but not copy data because show the message
i hope some body help
Sub Test()
Dim file_name As Variant
Dim open_wk As Workbook
On Error GoTo 1
file_name = Application.GetOpenFilename(Title:="choose the file ", FileFilter:="Excel Files *.xlsx (*.xlsx),")
If file_name = False Then1 MsgBox "name of the file is not correct", vbCritical
Exit Sub
Else
Set open_wk = Workbooks.Open(file_name)
EndIf
Windows("TT1.xlsx").Activate
Sheets("sheet1").Select
Range("a2:E15").Select
Selection.CopyThisWorkbook.Activate
Sheets("sheet1").Select
Range("b2").Select
Selection.PasteSpecial Paste:=xlPasteValues
ThisWorkbook.Close
Application.CutCopyMode = False
End Sub