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
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
A1
on Sheet1
B2
on Sheet2
Button2
which opens the formCommandButton1
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
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.
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.