Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-16-2015, 05:15 AM
rosscortb rosscortb is offline text based on Combo box selection Windows XP text based on Combo box selection Office 2010 32bit
Novice
text based on Combo box selection
 
Join Date: May 2014
Posts: 17
rosscortb is on a distinguished road
Default text based on Combo box selection

Hi

Word 2010

I have a combo box, with Engineer an option.

I have a bookmark also called Grade, If Engineer is select then Grade should equal D

Private Sub UserForm_Initialize()
With Me.cboPosition
.AddItem "Engineer"

End With
End Sub

Private Sub cmdOk_Click()

Selection.GoTo What:=wdGoToBookmark, Name:="Position"
Selection.TypeText Me.cboPosition


If Me.cboPosition = True Then
Selection.GoTo What:=wdGoToBookmark, Name:="Grade"
Selection.TypeText "E"


How do I Get the word E to display?



Thanks

Ross
Reply With Quote
  #2  
Old 03-16-2015, 05:41 AM
gmaxey gmaxey is offline text based on Combo box selection Windows 7 32bit text based on Combo box selection Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Private Sub UserForm_Initialize()
  With cboPosition
    .AddItem "Nub"
    .AddItem "Journeyman"
    .AddItem "Engineer"
  End With
End Sub
Private Sub cmdOK_Click()
  If cboPosition.Value = "Engineer" Then
    WriteToBM "Grade", "E"
  End If
  Hide
End Sub
Sub WriteToBM(strName As String, strText As String)
Dim oRng As Word.Range
  Set oRng = ActiveDocument.Bookmarks(strName).Range
  oRng.Text = strText
  ActiveDocument.Bookmarks.Add strName, oRng
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 03-16-2015, 09:07 AM
rosscortb rosscortb is offline text based on Combo box selection Windows XP text based on Combo box selection Office 2010 32bit
Novice
text based on Combo box selection
 
Join Date: May 2014
Posts: 17
rosscortb is on a distinguished road
Default

Thanks

When Engineer is selected I also wanted the word "Engineer" to appear in the bookmark called position

Selection.GoTo What:=wdGoToBookmark, Name:="Position"
Selection.TypeText Me.cboPosition


Private Sub UserForm_Initialize()
With cboPosition
.AddItem "Nub"
.AddItem "Journeyman"
.AddItem "Engineer"
End With
End Sub
Private Sub cmdOK_Click()
If cboPosition.Value = "Engineer" Then
WriteToBM "Grade", "E"
End If
Hide

Selection.GoTo What:=wdGoToBookmark, Name:="Position"
Selection.TypeText Me.cboPosition
End If
Unload Me

End Sub
Sub WriteToBM(strName As String, strText As String)
Dim oRng As Word.Range
Set oRng = ActiveDocument.Bookmarks(strName).Range
oRng.Text = strText
ActiveDocument.Bookmarks.Add strName, oRng
End Sub


Ross

Last edited by rosscortb; 03-16-2015 at 09:10 AM. Reason: Added Code
Reply With Quote
  #4  
Old 03-16-2015, 06:57 PM
gmaxey gmaxey is offline text based on Combo box selection Windows 7 32bit text based on Combo box selection Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Come on Ross!

WriteToBookmark, "Position", cboPosition.Value
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide/Unhide Text Based on Drop Down Selection gw1500se Word 3 02-19-2015 12:17 PM
text based on Combo box selection Show/Hide Text based on Checkbox Selection tammytran105 Word VBA 7 10-02-2014 04:30 PM
text based on Combo box selection Hide/Unhide a Block of Text Based on Choice Selection inquirer Word VBA 7 09-22-2014 04:41 PM
Display paragraph of text based on value selected in combo WordWaza Word 0 08-09-2013 06:30 AM
Macro to populate a text form field based on dropdown selection koloa Word 0 10-20-2011 11:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:35 AM.


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