Solved

Set sequence of worksheets in WorkBook_Open

Posted on 2012-04-02
2
257 Views
Last Modified: 2012-04-02
Hello Experts,

I have a workbook for distribution - I do not need to personalize the ribbon, but I do want to keep the worksheets in the same sequence.  If the end-user should move them around - I would like to have them reset to my set sequence on Workbook_Open.

They do not fall in alphabetic order and there are a few sheets that I want out of numeric sequence.  I have 17 sheets - I do not mind having it layed out in 17 steps on Open to put them in sequence.

Any help would be appreciated,
Thanks
0
Comment
Question by:mike637
2 Comments
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
ID: 37797740
This is doable, though you can achieve the same thing (keep the user from moving sheets) via workbook protection.  Here's the code that goes in ThisWorkbook:

Private Sub Workbook_Open()
    Call reSequenceSheets
End Sub

Open in new window


And, the simple sort algorithm will be to start with the last sheet, end with the first sheet in sequence, and then just move that sheet before sheet 1.  At the end, the sheets are sorted in the sequence you desire.

I put the sheet sequence in the code, though this could easily be read in from a spreadsheet, as well.  Given there are only 17 to worry about, setting a comma delimited constant with the sheet names in the correct order seemed a good approach.

So, just change the constant, below, to be the order you want to retain the sheets in on the open event.

The following goes in a public module:

Option Explicit
Const shtOrder = "Sheet1,Sheet2,Sheet3,Sheet4,Sheet5,Sheet6,Sheet7,Sheet8,Sheet9,Sheet10,Sheet11,Sheet12,Sheet13,Sheet14,Sheet15,Sheet16,Sheet17"
Sub reSequenceSheets()
Dim wkb As Workbook
Dim vSheets As Variant
Dim i As Long

    Application.ScreenUpdating = False
    
    Set wkb = ThisWorkbook
    
    vSheets = Split(shtOrder, ",")
    
    For i = UBound(vSheets) To LBound(vSheets) Step -1
        wkb.Sheets(vSheets(i)).Move before:=wkb.Sheets(1)
    Next i

    Application.ScreenUpdating = True
    
End Sub

Open in new window


Download the attached, reorder the sheets and save.  When you open the file, the sheets should be back to the correct order.

Enjoy!

Dave
reSequenceSheetsOnOpen-r1.xlsm
0
 

Author Closing Comment

by:mike637
ID: 37798667
Thank you very much for your guidance and expertise.

Michael
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question