you can not have 2 subs named switch, comment out the original or change name of one you are not using
Quote:
just replace your existing switch procedure
Printable View
you can not have 2 subs named switch, comment out the original or change name of one you are not using
Quote:
just replace your existing switch procedure
I get compile error on nexsht = 1
This is module 1:
Code:Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub pause()
Dim pause As Worksheet
Do
For Each pause In ThisWorkbook.Worksheets
pause.Activate
Application.Wait Now + TimeValue("00:00:15")
End Sub
Sub Switch()
If GetAsyncKeyState(vbKeyShift) Then Exit Sub
If ActiveSheet.Index = Sheets.Count Then
nexsht = 1
Else: nexsht = ActiveSheet.Index + 1
End If
heets(nexsht).ActivateApplication.OnTime Now + TimeValue("00:00:15"), "Switch"
End Sub
any particular error or just some random error each time?Quote:
I get compile error on nexsht = 1
you should declare nexsht as integer
It just says compile error. How do I declare nexsht as integer? I just put that line somewhere? Sorry I'm a noob.
When I try this, sheets get's highlighted and I get a runtime error 438Code:Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub pause()
Dim pause As Worksheet
Do
For Each pause In ThisWorkbook.Worksheets
pause.Activate
Application.Wait Now + TimeValue("00:00:15")
End Sub
Sub Switch()
If GetAsyncKeyState(vbKeyShift) Then Exit Sub
If ActiveSheet.Index = Sheets.Count Then
Dim nexsht As Integer
nexsht = 1
Else: nexsht = ActiveSheet.Index + 1
End If
Sheets(nexsht).ActivateApplication.OnTime Now + TimeValue("00:00:15"), "Switch"
End Sub
i can see this line would cause errorQuote:
Sheets(nexsht).ActivateApplication.OnTime Now + TimeValue("00:00:15"), "Switch"
you could look at the original code i posted, to see how it should be
I think you lost me. That code didn't work remember? What is this code you just posted?
try reading back all the posts till you find where you copied the above line from
Huh? But that code doesn't work. Still lost.
but did you find why it gave error?
I have no idea on any error. This is the first time I've even approached VB. I am completely new and nothing about it, which is why I cam to this forum. I really need someone to lay out the code so I can test it.
but you have to copy correctlyQuote:
I really need someone to lay out the code so I can test it.
Okay here is what I have now:
works!!!!!Code:Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub pause()
Dim pause As Worksheet
Do
For Each pause In ThisWorkbook.Worksheets
pause.Activate
Application.Wait Now + TimeValue("00:00:15")
End Sub
Sub Switch()
If GetAsyncKeyState(vbKeyShift) Then Exit Sub
If ActiveSheet.Index = Sheets.Count Then
Dim nexsht as Integer
nexsht = 1
Else: nexsht = ActiveSheet.Index + 1
End If
Sheets(nexsht).Activate
Application.OnTime Now + TimeValue("00:00:15"), "Switch"
End Sub