leal72
06-22-2012, 09:16 AM
Public Sub MovePreviousDayDailyLog()
Dim IsWorkbookOpen As Boolean
Dim i As Integer
For i = 1 To Workbooks.Count
If Workbooks(i).Name = "Daily Logs.xlsx" Then
IsWorkbookOpen = True
Exit For
End If
Next
If IsWorkbookOpen = False Then
Workbooks.Open (ThisWorkbook.Path & "\Daily Logs.xlsx")
End If
IsWorkbookOpen = False
Workbooks("Main Log").Sheets(2).Move after:=Workbooks("Daily Logs.xlsx").Sheets(1)
Workbooks("Daily Logs").Close savechanges:=True
End Sub
I open the Main Log.xlsm file and get a "script out of range" error and the debug takes me to the line in bold print. The macro runs as soon as the Main Log book is opened. I need to fix the error but not having a luck so far.
Dim IsWorkbookOpen As Boolean
Dim i As Integer
For i = 1 To Workbooks.Count
If Workbooks(i).Name = "Daily Logs.xlsx" Then
IsWorkbookOpen = True
Exit For
End If
Next
If IsWorkbookOpen = False Then
Workbooks.Open (ThisWorkbook.Path & "\Daily Logs.xlsx")
End If
IsWorkbookOpen = False
Workbooks("Main Log").Sheets(2).Move after:=Workbooks("Daily Logs.xlsx").Sheets(1)
Workbooks("Daily Logs").Close savechanges:=True
End Sub
I open the Main Log.xlsm file and get a "script out of range" error and the debug takes me to the line in bold print. The macro runs as soon as the Main Log book is opened. I need to fix the error but not having a luck so far.