Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2011, 12:16 AM
ilkks ilkks is offline Code to export value from ComboBox Windows Vista Code to export value from ComboBox Office 2007
Novice
Code to export value from ComboBox
 
Join Date: May 2011
Posts: 23
ilkks is on a distinguished road
Default Code to export value from ComboBox

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
And it exports the chosen value by updating it to the bookmark. It works, But I want it to be exported as text that overrides the MACROBUTTON.



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
Reply With Quote
  #2  
Old 05-24-2011, 09:51 PM
macropod's Avatar
macropod macropod is offline Code to export value from ComboBox Windows 7 32bit Code to export value from ComboBox Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Do you want to delete the macrobutton field, or just update its contents?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-24-2011, 11:09 PM
ilkks ilkks is offline Code to export value from ComboBox Windows Vista Code to export value from ComboBox Office 2007
Novice
Code to export value from ComboBox
 
Join Date: May 2011
Posts: 23
ilkks is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 05-25-2011, 02:29 AM
macropod's Avatar
macropod macropod is offline Code to export value from ComboBox Windows 7 32bit Code to export value from ComboBox Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi ilkks,

Try:
Code:
Private Sub cmdOK_Click()
Selection.Fields(1).Code.Text = "MACROBUTTON Update " & cboFood.Value
Unload Me
End Sub
where 'Update' is the name of the sub called by your MACROBUTTON.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-25-2011, 03:16 AM
ilkks ilkks is offline Code to export value from ComboBox Windows Vista Code to export value from ComboBox Office 2007
Novice
Code to export value from ComboBox
 
Join Date: May 2011
Posts: 23
ilkks is on a distinguished road
Default

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.
The sub called by my MacroButton is called FoodDropDownList, and it is like this:

Code:
Sub FoodDropDownList()

    frmTesti.Show
    
End Sub
And therefore here is the code I tested by your instructions which makes the run-time error:

Code:
Private Sub cmdOK_Click()

Selection.Fields(1).Code.Text = "MACROBUTTON FoodDropDownList" & cboFood.Value
Unload Me

End Sub
Reply With Quote
  #6  
Old 05-25-2011, 03:21 AM
ilkks ilkks is offline Code to export value from ComboBox Windows Vista Code to export value from ComboBox Office 2007
Novice
Code to export value from ComboBox
 
Join Date: May 2011
Posts: 23
ilkks is on a distinguished road
Default

Post removed
Reply With Quote
  #7  
Old 05-25-2011, 03:35 AM
macropod's Avatar
macropod macropod is offline Code to export value from ComboBox Windows 7 32bit Code to export value from ComboBox Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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.
Attached Files
File Type: doc Macrobutton.doc (42.0 KB, 17 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 05-25-2011, 04:06 AM
ilkks ilkks is offline Code to export value from ComboBox Windows Vista Code to export value from ComboBox Office 2007
Novice
Code to export value from ComboBox
 
Join Date: May 2011
Posts: 23
ilkks is on a distinguished road
Default

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!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
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
Code to export value from ComboBox Array into ComboBox + Macro-Text into ActiveDocument Vivi Word VBA 1 01-27-2010 07:03 AM
Code to export value from ComboBox Combobox manipulation vsempoux Word VBA 3 10-31-2009 08:58 AM
Export/Import Arkmom Outlook 0 03-31-2009 02:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft