Consulting

Results 1 to 3 of 3

Thread: Delete WB-Open sub as WB is saved

  1. #1

    Delete WB-Open sub as WB is saved

    I have a Workbook_open event that hides all but one of the sheets.

    I then have a sub that allows the user to select the sheets they want to keep visible and use.

    I want to disable the WB-Open routine as the WB is saved for the first time (so next time its opened the sheets selected will appear only). I will prompt a rename of the WB at that point

    Assume the instruction would be in the 'before save' or 'before close' event.

    Not sure how to go about deleting the WB_open code.

    Any help appreciated
    regards
    Jon

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not tested, but try something like this

    [vba]

    Private Sub Workbook_Open()
    Dim fReOpen As Boolean

    On Error Resume Next
    fReOpen = Application.Evaluate(Me.Names("_ReOpen").RefersTo)
    On Error GoTo 0
    If Not fReOpen Then

    Call HideAllSheets
    ThisWorkbook.Names.Add Name:="_ReOpen", RefersTo:="=TRUE"
    End If

    End Sub
    [/vBa]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Alternatively, make your workbook a template.
    A freshly opened file from a template has no path:

    If Thisworkbook.Path="" and not Thisworkbook.Name Like "*.xlt" Then
    'Hide sheets here
    End If
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •