![]() |
#1
|
|||
|
|||
![]()
I have MACROBUTTON, that launches UserForm, that contains ComboBox. What is the code to export chosen value from ComboBox to document as text.
I have this code: Code:
Private Sub UserForm_Initialize() With cboFood .AddItem "Apple" .AddItem "Pie" .AddItem "Meat" .AddItem "Squirrel" .AddItem "Banana" .AddItem "Nuts" End With End Sub ____________________________________ Private Sub cmdOK_Click() With ActiveDocument .Bookmarks("Food).Range.Text = cboFood.Value End With Application.ScreenUpdating = True Unload Me End Sub I think the code that I am looking for is something like this: Code:
Private Sub cmdOK_Click() Selection.TypeText Text:="cboFood.Value" Unload Me End Sub |
#2
|
||||
|
||||
![]()
Do you want to delete the macrobutton field, or just update its contents?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Well, the best option would be this:
There is MacroButton-field and its DisplayText says: "Double-click me to open Combobox". And then you choose the value that you want from the dropdownlist of combobox. Then the chosen value replaces the DisplayText of MacroButton. This way it would be possible to double-click again the MacroButton-field and choose/change new values if necessary. --------- But I would be happy even if the MacroButton gets deleted. I just need to get the chosen value from ComboBox to document as text. |
#4
|
||||
|
||||
![]()
Hi ilkks,
Try: Code:
Private Sub cmdOK_Click() Selection.Fields(1).Code.Text = "MACROBUTTON Update " & cboFood.Value Unload Me End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Thank you for your reply macropod.
I can see and choose all values in the UserForm/ComboBox, but when I press cmdOK_Click-button it says: Code:
Run-time error: 5941 The requested member of the collection does not exists. Code:
Sub FoodDropDownList() frmTesti.Show End Sub Code:
Private Sub cmdOK_Click() Selection.Fields(1).Code.Text = "MACROBUTTON FoodDropDownList" & cboFood.Value Unload Me End Sub |
#6
|
|||
|
|||
![]()
Post removed
|
#7
|
||||
|
||||
![]()
Hi ilkks,
Works for me! You do need to have a space here though: "MACROBUTTON FoodDropDownList " & cboFood.Value not: "MACROBUTTON FoodDropDownList" & cboFood.Value See attached.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
![]()
Nevermind my previous post. It said the error when I tested code in Visual Basic Editor by F5. But when I executed the Macrobutton from the document it worked like a charm!
Thank you very much macropod for the help! |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Textbox updating from combobox selection | paxile2k | Word VBA | 0 | 10-26-2010 02:30 PM |
How to use the content of a combobox for {IF} field? | Melaanie | Word | 0 | 06-14-2010 02:00 AM |
![]() |
Vivi | Word VBA | 1 | 01-27-2010 07:03 AM |
![]() |
vsempoux | Word VBA | 3 | 10-31-2009 08:58 AM |
Export/Import | Arkmom | Outlook | 0 | 03-31-2009 02:47 PM |