-
Solved: Need help to understand this code
[vba]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[/vba]
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.
-
Maybe you should use LCase and the xlsm file extension in your Workbooks? The need for the file extension can vary depending on the user's Windows setting.
[vba]Public Sub MovePreviousDayDailyLog()
Dim IsWorkbookOpen As Boolean
Dim i As Integer
For i = 1 To Workbooks.Count
If LCase(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.xlsm").Sheets(2).Move after:=Workbooks("Daily Logs.xlsx").Sheets(1)
Workbooks("Daily Logs.xlsx").Close savechanges:=True
End Sub[/vba]
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules