• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Open file to specific sheet - getting 'ambiguous' error

Rodger

Member
I am trying to add a code to open a workbook to the 'main menu' tab
The code I usually use is

Code:
Private Sub Workbook_Open()
    Worksheets("main page").Activate
    Application.DisplayFullScreen = True
  
End Sub

But it seems to be conflicting with this code that is working perfectly on its own.

Code:
Option Explicit

Private bRangeEdited As Boolean
Private WithEvents ws As Worksheet


Private Sub Workbook_Open()
    Set ws = Range("InputRangeItems").Parent
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim sMSG As String
   
    sMSG = "This will lock the new Inventory Items and Prices you entered, and you won't be able to change them." & vbLf
    sMSG = sMSG & "Do you want to go ahead ?"
    If Not bRangeEdited Then GoTo Xit
    If Not Me.ReadOnly Then
        With Range("InputRangeItems")
            If MsgBox(sMSG, vbExclamation + vbYesNo) = vbNo Then
                Cancel = True
                GoTo Xit
            End If
            .Parent.Unprotect ""
            If .SpecialCells(xlCellTypeBlanks).Address <> .Address Then
                .SpecialCells(xlCellTypeConstants).Locked = True
                bRangeEdited = False
            End If
            .Parent.Protect ""
        End With
    End If
Xit:
End Sub

Private Sub ws_Change(ByVal Target As Range)
    If Not Intersect(Range("InputRangeItems"), Target) Is Nothing Then
        bRangeEdited = True
    End If
   
End Sub

I'm sure it's something pretty simple, but I am a pretty simple guy!

Thanks for taking a look.

Rodger
 
You can only have one Workbook_Open event in a workbook.

Combine the two in single event code.
 
That was a fast reply!
And, yep, that was it - working great now
Thanks for the help (and lesson)

Cheers !
 
Back
Top