In the following code (this is at the end of the macro) the opened csv doesn't close when the code above Else runs, but when the code below Else runs it does, the csv is saved because when I close there is no request to save and all data remains.
Is there a way to change this so it saves and closes without me having to after this code finishes?
filetoopen = ThisWorkbook.Worksheets("CSV COLLECT").Range("V3")
Workbooks.Open fileName:=filetoopen
If Not IsEmpty(Range("A1")) = True Then
ThisWorkbook.Worksheets("COLLECT HIS").Range("C9").Copy
Range("A1").End(xlDown).Offset(1).PasteSpecial xlValues
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CalculateFullRebuild
For Each wsheet In ThisWorkbook.Worksheets
wsheet.PROTECT Password:="TRADE"
Next wsheet
ThisWorkbook.Worksheets("COLLECT HIS").Activate
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Else
End If
filetoopen = ThisWorkbook.Worksheets("CSV COLLECT").Range("V3")
ThisWorkbook.Worksheets("COLLECT HIS").Range("C8:C9").Copy
Workbooks.Open fileName:=filetoopen
If IsEmpty(Range("A1")) = True Then
Range("A1").PasteSpecial xlValues
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CalculateFullRebuild
For Each wsheet In ThisWorkbook.Worksheets
wsheet.PROTECT Password:="TRADE"
Next wsheet
Worksheets("COLLECT HIS").Activate
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
End If
End Sub
Is there a way to change this so it saves and closes without me having to after this code finishes?
filetoopen = ThisWorkbook.Worksheets("CSV COLLECT").Range("V3")
Workbooks.Open fileName:=filetoopen
If Not IsEmpty(Range("A1")) = True Then
ThisWorkbook.Worksheets("COLLECT HIS").Range("C9").Copy
Range("A1").End(xlDown).Offset(1).PasteSpecial xlValues
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CalculateFullRebuild
For Each wsheet In ThisWorkbook.Worksheets
wsheet.PROTECT Password:="TRADE"
Next wsheet
ThisWorkbook.Worksheets("COLLECT HIS").Activate
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Else
End If
filetoopen = ThisWorkbook.Worksheets("CSV COLLECT").Range("V3")
ThisWorkbook.Worksheets("COLLECT HIS").Range("C8:C9").Copy
Workbooks.Open fileName:=filetoopen
If IsEmpty(Range("A1")) = True Then
Range("A1").PasteSpecial xlValues
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CalculateFullRebuild
For Each wsheet In ThisWorkbook.Worksheets
wsheet.PROTECT Password:="TRADE"
Next wsheet
Worksheets("COLLECT HIS").Activate
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
End If
End Sub