Beginner

B

Bobby

Hello community,
I worte the following code:
------------------------------------
Private Sub ListBox1_Click()
Dim WriteHere As Range
Set WriteHere = ActiveDocument.Paragraphs(2).Range
WriteHere.InsertAfter UserForm1.ListBox1.Value
Set WriteHere = Nothing
End Sub
Private Sub UserForm_Initialize()
UserForm1.ListBox1.AddItem "ACHAT"
UserForm1.ListBox1.AddItem "VENTE"
UserForm1.ListBox1.AddItem "MODIFICATION"
UserForm1.ListBox1.AddItem "SUPPRESSION" '
UserForm1.Show
Unload Me ' referme la boîte contenant ListBox1
End Sub
----------------------------------
1. The Listbox will not close
2, I get the following message:
Run-Time error 91
Object variable or With block not set

Any help will be appreciated!
Thank's ahead
 
T

They call me Trinity

Bobby said:
Hello community,
I worte the following code:
------------------------------------
Private Sub ListBox1_Click()
Dim WriteHere As Range
Set WriteHere = ActiveDocument.Paragraphs(2).Range
WriteHere.InsertAfter UserForm1.ListBox1.Value
Set WriteHere = Nothing
End Sub
Private Sub UserForm_Initialize()
UserForm1.ListBox1.AddItem "ACHAT"
UserForm1.ListBox1.AddItem "VENTE"
UserForm1.ListBox1.AddItem "MODIFICATION"
UserForm1.ListBox1.AddItem "SUPPRESSION" '
UserForm1.Show
Unload Me ' referme la boîte contenant ListBox1
End Sub ----------------------------------
1. The Listbox will not close
2, I get the following message:
Run-Time error 91
Object variable or With block not set
Any help will be appreciated!
Thank's ahead

Hi,

Remove 'Userform1.Show' and 'Unload Me' from the UserForm_Initialize event.
Those lines should be in the method used to display the form e.g.

Public Sub foo

Userform1.Show
Unload Userform1

End Sub

Regards
MC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top