Why do I keep getting compile error

ghrek

Active Member
Joined
Jul 29, 2005
Messages
426
Hi

I have the following macro and keep getting compile error expected end sub. Any ideas?

VBA Code:
    Sheets("WORLDLINEMACHINES").Select
    With ActiveSheet
        .Unprotect Password:="s"
    Sheets("Sheet2").Select
     With ActiveSheet
        .Unprotect Password:="s"
    Sheets("WORLDLINEMACHINES").Select
    Range("A11:M57").Select
    ActiveWindow.SmallScroll Down:=-45
    Selection.PrintOut Copies:=2, Collate:=True
    Sheets("Sheet2").Select
    Selection.PrintOut Copies:=2, Collate:=True
    Sheets("Sheet2").Select
     With ActiveSheet
        .Protect Password:="s"
    Sheets("WORLDLINEMACHINES").Select
     With ActiveSheet
        .Protect Password:="s"
    ActiveWorkbook.Save
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You're missing 'End With' in 4 places.
Cleaning it up a bit, see if this works.
VBA Code:
Sub test()
    With Sheets("WORLDLINEMACHINES")
        .Unprotect Password:="s"
        .Range("A11:M57").PrintOut Copies:=2, Collate:=True
        .Protect Password:="s"
    End With
        With Sheets("WORLDLINEMACHINES")
        .Unprotect Password:="s"
        .PrintOut Copies:=2, Collate:=True
        .Protect Password:="s"
    End With

    ActiveWorkbook.Save
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top