Excel 2013 worksheet activate

前端 未结 9 1742
情话喂你
情话喂你 2021-01-03 03:28

I have an issue with activating a sheet from a user form, the same code works fine in Excel 2003 to Excel 2010, doesn\'t work with Excel 2013.

This is how to simply

相关标签:
9条回答
  • 2021-01-03 03:54

    Wow, I was able to reproduce this error using 2013. This is a fantastic failure of Excel's new SDI Interface. What is also interestingly odd is that when you follow the following steps

    • Select cell A1 on Sheet1
    • Select cell B2 on Sheet2
    • Click Button2 which opens the form
    • Click the CommandButton1 on the form (which hides the form and activates Sheet2)

    it looks like cell B2 on Sheet2 is selected, but when you start typing, the text is going into cell A1; Once you hit Enter the text disappears to cell B2 on Sheet1

    You almost have to see it to believe it.

    The only thing that I've found that works is using the Ontime function.

    Private Sub CommandButton1_Click()
        Unload Me
        'Call Macro1
        Application.OnTime Now(), "Macro1"
    End Sub
    

    ...but I have a feeling that this isn't going to help everyone

    0 讨论(0)
  • 2021-01-03 03:55

    I have the same problem, but my code is actually running in a Excel COM addin, which is slightly different from VBA.

    My code worked in 2003,2010... using Sheets("Sheet2").Activate, but not 2013

    But I fixed the problem by starting a timer, 100 ms after my event code (Button event).

    Then this trimmer opens the file and uses Sheets("Sheet2").Activate. It is then select, just the same as it used to be in old versions.

    0 讨论(0)
  • 2021-01-03 03:57

    I was able to reproduce the error in Excel 2013 as per Profex's answer. A workaround that solved the issue for me was to make my userform modeless.

    userform1.show vbModeless
    

    I understand that this workaround won't be helpful if you require a modal form, but hopefully it will save the next person some time.

    0 讨论(0)
提交回复
热议问题