I'm having some trouble with the ActiveWorkbook.Close actions in Excel VBA.
The macro is closing the ControlFile instead of the active sheet. Is there another way to do this or does anyone know where I am going wrong in the code?
Dim tabname As String
Sheets("Menu").Select
Range("TodayDOW").Select
tabname = ActiveCell.Value
ControlFile = ActiveWorkbook.Name
Workbooks.Open Filename:=FilepathDOW
Sheets(tabname).Select
ActiveSheet.Name = tabname
Sheets(tabname).Copy After:=Workbooks(ControlFile).Sheets(1)
Windows(FilenameDOW).Activate
ActiveWorkbook.Close SaveChanges:=False
Windows(ControlFile).Activate
Sheets("Menu").Select
Range("E8").Select
'WORKS GREAT SO FAR!!!!!!!!!!!!!!! Problem starts in the next process
Dim ws As Worksheet
On Error Resume Next
Set ws = ThisWorkbook.Worksheets("Daily")
If Err > 0 Then
Err.Clear
Else
Sheets("Daily").Activate
ActiveWindow.SelectedSheets.Delete
End If
Sheets("Menu").Select
TabNameDaily = "Daily"
ControlFile = ActiveWorkbook.Name
Workbooks.Open Filename:=FilepathDD
Sheets("Daily").Activate
ActiveSheet.Name = TabNameDaily
Sheets(TabNameDaily).Copy After:=Workbooks(ControlFile).Sheets(2)
' it's closing the main workbook instead of the imported book
Windows(FilenameDD).Activate
ActiveWorkbook.Close SaveChanges:=False
Windows(ControlFile).Activate
'importing the next file
Dim ws2 As Worksheet
On Error Resume Next
Bookmarks