I am trying to create a small tutorial for one of my Excel Applications and I am running into the issue where I'm trying to draw a text shape to the screen to give advice on what to enter into an InputBox
but the InputBox
gets displayed before the text shape, however, when running in debug mode and stepping through the code it all works fine.
There is one userform ufNext
which only contains one button, ufNext
. The click event code for this button contains a Select Case
clause to determine what to do each time it is clicked. The value the clause is checking is a Public
variable, tutSectionsRun
Option Explicit
Private Sub btnNext_Click()
Select Case tutSectionsRun
Case 1
Call Section2
Case 2
Call Section3
Call MPFilterString
' Case N
' ...
End Select
End Sub
The code starts in Section1
which just sets the position of ufNext
and shows the form then sets the global variable tutSectionsRun
to 1
.
The user clicks the "Next" button on the ufNext
form and it calls Section2
which re-positions the form (there would normally be other code in these "Section" procedures), and sets the global variable to 2
.
Again, the user clicks the "Next" button but this time there is the issue where before the shapes are drawn to the screen, I get the InputBox
popping up first and only after it closes the text shape tutText
is drawn to the screen.
Option Explicit
Public tutSectionsRun As Long
Sub Section1()
ufNext.Left = 550
ufNext.Top = 450
ufNext.Show
tutSectionsRun = 1
End Sub
Sub Section2()
ufNext.Left = 910
ufNext.Top = 350
tutSectionsRun = 2
End Sub
Sub Section3()
Dim tutText As Shape
Set tutText = ActiveSheet.Shapes.AddLabel(msoTextOrientationHorizontal, 600, 300, 200, 100)
tutText.TextFrame2.TextRange.Text = "Enter the string ""gr"" into the input box."
tutText.Locked = False
ufNext.Hide
tutSectionsRun = 3
End Sub
Sub MPFilterString()
Dim s As Variant
Application.ScreenUpdating = False
s = Application.InputBox("Enter string to filter out.", "Filter String.")
If s = False Then Exit Sub
End Sub
**Edit : I forgot to mention that the userform is non-modal. Otherwise execution would pause on the call to ufNext.Show
and clicking next would call the event handler before the tutSectionsRun
variable had been set to 1