Leonardo1234
Member
Code:
Sub TEST()
Dim wbSource As Workbook, wbDay1 As Workbook, wbDay2 As Workbook
Dim wsSource As Worksheet
Dim SourceFile As String, Day2 As String
Dim fso As Object
Application.ScreenUpdating = False
Set fso = CreateObject("Scripting.FileSystemObject")
Set wbDay1 = ThisWorkbook
SourceFile = Environ("UserProfile") & "\Desktop\Stock Market\Sholtan War\1.xlsm"
Day2 = Environ("UserProfile") & "\Desktop\Stock Market\Sholtan War\Day2.xlsb"
If Not fso.FileExists(SourceFile) Then
MsgBox "The file " & SourceFile & " doesn't exist.", vbExclamation
Exit Sub
ElseIf Not fso.FileExists(Day2) Then
MsgBox "The file " & Day2 & " doesn't exist.", vbExclamation
Exit Sub
End If
Set wbSource = Workbooks.Open(SourceFile)
Set wbDay2 = Workbooks.Open(Day2)
wbDay1.Sheets("Sheet1").Cells.Clear
wbDay2.Sheets("Sheet1").Cells.Clear
Set wsSource = wbSource.Sheets("1")
wsSource.Cells.Copy
wbDay2.Sheets("Sheet1").Range("A1").PasteSpecial xlPasteAll
wbDay1.Sheets("Sheet1").Range("A1").PasteSpecial xlPasteAll
Application.CutCopyMode = 0
wbSource.Close False
wbDay2.Close True
wbDay1.Sheets("Sheet1").Range("A1").Select
wbDay1.Save
Application.ScreenUpdating = True
MsgBox "Data has been copied successfully.", vbInformation
End Sub