Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Excel VB script to change sheet over certain period  (Read 4921 times)

0 Members and 1 Guest are viewing this topic.

Akod

    Topic Starter


    Rookie

    • Certifications: List
    • Experience: Experienced
    • OS: Windows 7
    Excel VB script to change sheet over certain period
    « on: September 15, 2014, 10:34:00 AM »
    Hello,

    Please i want to display different information in different excel sheets and project it on a dashboard.
    Can someone help me with a VB script to automatically switch sheets over a set period of time.

    For example: Excel workbook contains 5 sheets; sheet1, sheet2, sheet3, sheet4 & sheet5.
    The code will automatically switch from sheet1 to sheet2 after 30 seconds.

    If an addin or a software can assist me with this situation i will be glad.

    Counting on you all!

    Thanks.


    strollin



      Adviser
    • Thanked: 84
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Guru
    • OS: Windows 10
    Re: Excel VB script to change sheet over certain period
    « Reply #1 on: September 15, 2014, 03:04:39 PM »
    Here's something basic that will cycle thru 5 sheets, displaying each sheet for 30 seconds.

    Code: [Select]
    Public RunWhen As Double
    Public Const cRunIntervalSeconds = 30 ' 30 seconds
    Public Const cRunWhat = "SwitchSheet"  ' the name of the sub to call

    Sub StartTimer()
        RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)  ' Current time + interval
        Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True
    End Sub

    Sub SwitchSheet()
        Dim SheetNum As Integer
        SheetNum = Sheets(ActiveSheet.Name).Index  ' current sheet number
        If SheetNum <= 4 Then  ' set value to 1 less than max sheets to cycle thru
           SheetNum = SheetNum + 1  ' increment to next sheet
        Else
           SheetNum = 1
        End If
        Worksheets(SheetNum).Activate  ' activate next sheet
        StartTimer  ' start timer for next cycle
    End Sub