0

I'll try to explain the situation:

I have a form, which is generated and designed programmatically.

So, I have an object instanced with this form: object "NewForm"

At some point, I need to show this form. So I have to add the object NewForm as a form:

VBA.UserForms.Add (NewForm.Name)

And then show the form,

UserForms(0).Hide
UserForms(0).Show

The problem is that I need to show a modeless form, so normally a simple

UserForms(0).Hide
UserForms(0).Show vbModeless

would be enought. However, when I use this last line of code, the form shows up and suddenly disappears.

I've also tried to set the property ShowModal as False, but I have the same result.

Thank you in advance,

Best regards

NOTE: I've tried using NewForm.Name.Show, and it doesn't work, so I have to use the collection instead.

Community
  • 1
  • 1
MGum
  • 3
  • 2
  • 1
    2 questions: 1) Why have you tried `NewForm.Name.Show` instead of just `NewForm.Show`, and 2) Why are you `.Hide`ing the form before you even `.Show` it? – Chronocidal Jun 25 '18 at 13:58
  • 1) I didn't mentioned, sorry, but If I use NewForm.Show, I get an error (property or method not generated by this object) 2)It's true that I don't need to Hide it, once it was never shown before. I removed the '.Hide', but the problem continues – MGum Jun 25 '18 at 14:23

1 Answers1

0

It depends how you execute the code. I tried a very simple test creating a dummy form called NewForm with nothing inside and executed the following code from the Immediate window of the VB editor:

Sub test_NewFrom()
    Dim mForm As NewForm
    Set mForm = New NewForm
    mForm.Show (vbModeless)
End Sub

the executions ends and the form is automatically closed as you described. Now if the test_NewFrom is a macro executed from an excel Event (for instance a shape layed out on a sheet surface) it will be displayed as expected.

pascal sautot
  • 375
  • 6
  • 20
  • I would like to thank you for this! I can use macro called from a shape on a sheet! That solves my problem! – MGum Jun 25 '18 at 14:49