PDA

View Full Version : Code to Force Macros Not working WHEN extended



Juriemagic
08-05-2015, 07:57 AM
Hi good people!,

I have a code that works just great on its own. The minute I add to the code, it simply opens the same sheet "Macros", whether or not macros is enabled. The code on its own is:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Visible = False
Application.CommandBars("Ply").Enabled = True
Dim ws As Worksheet
Sheets("Macros").Visible = True
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Macros" Then
ws.Visible = xlVeryHidden
End If
Next ws
End Sub
Private Sub Workbook_Open()
Dim ws As Worksheet
Sheets("Sheet1").Visible = True
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Then
ws.Visible = xlVeryHidden
End If
Next ws
End Sub


and with the rest is:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
application.Visible = False
application.CommandBars("Ply").Enabled = True
Dim ws As Worksheet
Sheets("Macros").Visible = True
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Macros" Then
ws.Visible = xlVeryHidden
End If
Next ws
End Sub
Private Sub Workbook_Open()
Sheets("LOG").Protect userinterfaceonly:=True
With application
.ScreenUpdating = False
.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",false)"
.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",true)"
.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",false)"
.ScreenUpdating = True
End With
application.CommandBars("Ply").Enabled = True
If Environ("userprofile") = "C:\Users\juriep" Then
Exit Sub
Else
Dim OutPut As Integer
OutPut = MsgBox("Illegal copy, Excel will now close", vbOKOnly, "")
If OutPut = 1 Then
application.Quit

End If
End If
Dim ws As Worksheet
Sheets("Report Type Stay Easy").Visible = True
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Report Type Stay Easy" Then
ws.Visible = xlVeryHidden
End If
Next ws
End Sub
Private Sub Workbook_SheetActivate(ByVal sh As Object)
If Environ("userprofile") = "C:\Users\juriep" Then
Exit Sub
Else
Dim OutPut As Integer
OutPut = MsgBox("Illegal copy, Excel will now close", vbOKOnly, "")
If OutPut = 1 Then

application.Quit
End If
End If
End Sub



Please would someone be so kind to help me out with this problem?. All and any help will be accepted with great humility and appreciation!..Thanx a lot