Evening, All!
I've come across a problem that I'm unable to find an answer to. Any help would be greatly appreciated. Please keep in mind that I don't consider myself an expert when it comes to VBA. I have learned a lot in the last couple years, but I'm definitely still learning. Anyway...my problem is as follows:
I have 5 versions of a workbook due to the size of the file. The largest one is 12.5MB and the smallest one is just over 1MB. I've written the code so that it can be used in any of the 5 workbooks, but today, I ran into an issue when running a procedure. Excel is crashing saying that "Method 'Activate' of Object '_Worksheet' Failed". I've been using this code for quite some time, so I don't understand why I'm seeing problems with it now. Here's my code.
Thank you in advance for any help. I'm sure my code isn't as efficient as it could be, so any hints would be appreciated as well.
~Daron
I've come across a problem that I'm unable to find an answer to. Any help would be greatly appreciated. Please keep in mind that I don't consider myself an expert when it comes to VBA. I have learned a lot in the last couple years, but I'm definitely still learning. Anyway...my problem is as follows:
I have 5 versions of a workbook due to the size of the file. The largest one is 12.5MB and the smallest one is just over 1MB. I've written the code so that it can be used in any of the 5 workbooks, but today, I ran into an issue when running a procedure. Excel is crashing saying that "Method 'Activate' of Object '_Worksheet' Failed". I've been using this code for quite some time, so I don't understand why I'm seeing problems with it now. Here's my code.
Code:
Sub Set_Print_Area()
Dim LR As String
Dim i As Long
For i = 1 To Worksheets.Count
If Worksheets(i).Name = "Start" Then
Exists = True
End If
Next i
If Exists Then
For i = 3 To 12
If Sheets(i).Visible = True Then
Sheets(i).Activate
If Range("C10") <> "" Then
ActiveSheet.Unprotect Password:="splicesheet"
LR = (Range("C10").Value + 9)
ActiveSheet.PageSetup.PrintArea = Range((Cells(1, 2)), (Cells(LR, 20))).Address
ActiveSheet.Protect Password:="splicesheet", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True
Range("H10").Select
End If
End If
Next i
Else
For i = 2 To 11
If Sheets(i).Visible = True Then
Sheets(i).Activate
If Range("C10") <> "" Then
ActiveSheet.Unprotect Password:="splicesheet"
LR = (Range("C10").Value + 9)
ActiveSheet.PageSetup.PrintArea = Range((Cells(1, 2)), (Cells(LR, 20))).Address
ActiveSheet.Protect Password:="splicesheet", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True
Range("H10").Select
End If
End If
Next i
End If
End Sub
Thank you in advance for any help. I'm sure my code isn't as efficient as it could be, so any hints would be appreciated as well.
~Daron