route217
asked on
One macro is prevent another from running......
Hi Experts
i have the following code which works prefectly for what it need to do.....
See Code:
But this code is prevent the following macro from running and openning up worksheet "Source Data"...which i need to work.....also
See Code....
i have the following code which works prefectly for what it need to do.....
See Code:
Option Explicit
Private Sub Workbook_Activate()
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim MySht As Worksheet
Set MySht = ActiveSheet
With Application
.ScreenUpdating = False
.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
.DisplayFormulaBar = False
.DisplayStatusBar = Not Application.DisplayStatusBar
End With
ActiveWindow.DisplayWorkbookTabs = False
Set wbBook = ThisWorkbook
For Each wsSheet In wbBook.Worksheets
With wsSheet
If Not .Name = "Blank" Then .Activate
With ActiveWindow
.DisplayHeadings = False
.DisplayGridlines = False
End With
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingRows:=True
End With
Next wsSheet
MySht.Select
End Sub
Private Sub Workbook_Deactivate()
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim MySht As Worksheet
Set MySht = ActiveSheet
With Application
.ScreenUpdating = False
.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
.DisplayFormulaBar = True
.DisplayStatusBar = True
End With
ActiveWindow.DisplayWorkbookTabs = True
Set wbBook = ThisWorkbook
For Each wsSheet In wbBook.Worksheets
With wsSheet
If Not .Name = "Blank" Then .Activate
With ActiveWindow
.DisplayHeadings = True
.DisplayGridlines = True
End With
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingRows:=True
End With
Next wsSheet
''RB: I have commented the below code out because (in theory - untested) this prevents the workbook from being deactivated (in fact, even the ".Activate" in the previous section may prevent deactivation.
' MySht.Select
End Sub
But this code is prevent the following macro from running and openning up worksheet "Source Data"...which i need to work.....also
See Code....
Option Explicit
Sub ToggleVisibilityOfDataWs()
Const MasterName As String = "Master"
Const pw As String = "secret"
With ThisWorkbook
If .ActiveSheet.Name = "Master" Then
With .Worksheets("Source Data")
If .Visible Then
.Visible = False
Else
If InputBox("Please enter password to show Source Data worksheet:", "ENTER PASSWORD...") = pw Then
.Visible = True
Else
MsgBox "Password incorrect!", vbOKOnly + vbInformation, "Macro Feedback..."
End If
End If
End With
Else
MsgBox "Can only run this macro from the worksheet called " & MasterName, vbOKOnly + vbInformation, "Macro Feedback..."
End If
End With
End Sub
ASKER
hi expert
I have changed the code as above and still cannot get the sheet to display. ..
I have changed the code as above and still cannot get the sheet to display. ..
ASKER
ok I have added...
activewindow.displayworkbo oktavs = True...
to the end of the code..
activewindow.displayworkbo
to the end of the code..
How would you know it is preventing? Is it displaying error messages?
ASKER
no worksheet tabs are visible on worksheet. ..
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
excellent work. ..perfectly. .
ASKER
shanan212
great feedback...can you kindly cast your eye over https://www.experts-exchange.com/questions/28174915/use-uerform-to-validated-data-in-source-sheet.html
regards
great feedback...can you kindly cast your eye over https://www.experts-exchange.com/questions/28174915/use-uerform-to-validated-data-in-source-sheet.html
regards
Open in new window
Try now.
I've added application.EnableEvents = false to disable the listener