|
-
Dec 15th, 2010, 04:09 PM
#41
Re: VB code not updating Excel Sheet 1
you can not have 2 subs named switch, comment out the original or change name of one you are not using
just replace your existing switch procedure
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 15th, 2010, 04:54 PM
#42
Thread Starter
Lively Member
Re: VB code not updating Excel Sheet 1
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
-
Dec 16th, 2010, 03:42 AM
#43
Re: VB code not updating Excel Sheet 1
I get compile error on nexsht = 1
any particular error or just some random error each time?
you should declare nexsht as integer
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 16th, 2010, 09:28 AM
#44
Thread Starter
Lively Member
Re: VB code not updating Excel Sheet 1
It just says compile error. How do I declare nexsht as integer? I just put that line somewhere? Sorry I'm a noob.
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).ActivateApplication.OnTime Now + TimeValue("00:00:15"), "Switch"
End Sub
When I try this, sheets get's highlighted and I get a runtime error 438
Last edited by sentinelace; Dec 16th, 2010 at 10:09 AM.
-
Dec 16th, 2010, 04:15 PM
#45
Re: VB code not updating Excel Sheet 1
Sheets(nexsht).ActivateApplication.OnTime Now + TimeValue("00:00:15"), "Switch"
i can see this line would cause error
you could look at the original code i posted, to see how it should be
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 16th, 2010, 04:29 PM
#46
Thread Starter
Lively Member
Re: VB code not updating Excel Sheet 1
I think you lost me. That code didn't work remember? What is this code you just posted?
-
Dec 16th, 2010, 09:57 PM
#47
Re: VB code not updating Excel Sheet 1
try reading back all the posts till you find where you copied the above line from
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 16th, 2010, 10:03 PM
#48
Thread Starter
Lively Member
Re: VB code not updating Excel Sheet 1
Huh? But that code doesn't work. Still lost.
-
Dec 17th, 2010, 02:47 AM
#49
Re: VB code not updating Excel Sheet 1
but did you find why it gave error?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 17th, 2010, 09:28 AM
#50
Thread Starter
Lively Member
Re: VB code not updating Excel Sheet 1
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.
-
Dec 17th, 2010, 09:42 PM
#51
Re: VB code not updating Excel Sheet 1
I really need someone to lay out the code so I can test it.
but you have to copy correctly
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 27th, 2010, 08:58 AM
#52
Thread Starter
Lively Member
Re: VB code not updating Excel Sheet 1
Okay here is what I have now:
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
works!!!!!
Last edited by sentinelace; Dec 27th, 2010 at 01:17 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|