Page 2 of 2 FirstFirst 12
Results 41 to 52 of 52

Thread: VB code not updating Excel Sheet 1

  1. #41
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  2. #42

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    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

  3. #43
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  4. #44

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    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.

  5. #45
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  6. #46

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    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?

  7. #47
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  8. #48

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: VB code not updating Excel Sheet 1

    Huh? But that code doesn't work. Still lost.

  9. #49
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  10. #50

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    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.

  11. #51
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  12. #52

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width