Solved

Set sequence of worksheets in WorkBook_Open

Posted on 2012-04-02
2
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
need count numbers IN ranges 25 30
NEED LOOK FOR NUM 23 29
Excel - IF criterion 2 23
Excel Conditional formatting - icon sets 5 11
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 article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

734 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