ComboBox

L

lj_iperen

I've just figured out how to work with VBA for word, but I seem to be
doing something wrong, and i don't know what it is, so: HELP!
This is what my macro looks like:

Sub ComboBox1_Change()
ComboBox1.AddItem "Nederland"
ComboBox1.AddItem "Europa"
ComboBox1.AddItem "Wereld"
End Sub

Somehow this works, until i close the word-document and open it again.
The macro's are still visible in vba, but the comboboxes in word are
empty again. I've looked all over the net to find out what i'm doing
wrong, but there is nothing more i can try.
 
H

Helmut Weber

Hi,

the combobox loses it's entries by design
when closing the doc, it seems,
except the current value, IMHO.

ComboBox1.AddItem "Nederland"
ComboBox1.AddItem "Europa"
ComboBox1.AddItem "Wereld"

With this in the change-event the
above values are added every time
the value (result) changes.

This is certainly not what you want.

You may use a commandbutton to add items,
or fill the list when opening the doc,
like:

Sub autoopen()
ComboBox1.AddItem "Nederland"
ComboBox1.AddItem "Europa"
ComboBox1.AddItem "Wereld"
End Sub

Private Sub ComboBox1_Change()
End Sub

Whereby "autoopen"
would be located in "ThisDocument"
for the actual project.

Have a look at the projects listed in the VBE.
ctrl r gets you the objects browser,
or whatever it is called in english.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
L

lj_iperen

Hi,

thecomboboxloses it's entries by design
when closing the doc, it seems,
except the current value, IMHO.


With this in the change-event the
above values are added every time
the value (result) changes.

This is certainly not what you want.

You may use a commandbutton to add items,
or fill the list when opening the doc,
like:

Sub autoopen()
ComboBox1.AddItem "Nederland"
ComboBox1.AddItem "Europa"
ComboBox1.AddItem "Wereld"
End Sub

Private Sub ComboBox1_Change()
End Sub

Whereby "autoopen"
would be located in "ThisDocument"
for the actual project.

Have a look at the projects listed in the VBE.
ctrl r gets you the objects browser,
or whatever it is called in english.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"




Sub autoopen()
ComboBox1.AddItem "Nederland"
ComboBox1.AddItem "Europa"
ComboBox1.AddItem "Wereld"
End Sub


This works, thank you very much!
 

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