|Your code works fine for me.|
Before I offer a possible solution, allow me to point out 2 things:
1 - The term Script isn't usually used when discussing VBA code. The more commonly used terms are either a Macro, "VBA code" or simply "code".
2 - Before you post any more code in this forum, please click on the Blue line at the end of this post and read the How To posted there. Thanks!
As far as your error, "Invalid outside procedure" usually means that you have stray line or comment outside of your actual code, i.e. before Private Sub or after End Sub.
The Option Explicit line is fine...that can be outside the macro, but any stray character or string will cause that error since the VBA editor doesn't know what to do with it.
Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.