Microsoft Office Tutorials and References
In Depth Information
Filling a Word Combo Box with Data from Excel
View the Appendix to learn how to store this procedure
in a Standard module (Word template).
Option explicit¶
' * * * * *¶
Sub AutoNew()¶
End Sub¶
' * * * * *¶
Sub GetUserInput()¶
'Variable declaration¶
Dim frm As frmUserInput¶
Dim doc As Word.Document¶
Set doc = ActiveDocument¶
If doc.Bookmarks.Count < 1 Then¶
MsgBox "Invalide document. " & _¶
"No bookmarks could be found.", _¶
vbCritical + vbOKOnly¶
Exit Sub¶
End If¶
Set frm = New frmUserInput¶
GetDataFromDocument frm, doc¶
'!Substitute the correct combo box name!¶
FillStateList frm.cboState¶
'!Substitute the correct combo box¶
'and text box names below!¶
frm.cboState.Text = frm.txtState.Text¶
If frm.Tag = "OK" Then¶
'!Substitute the correct combo box¶
'and text box names below!¶
frm.txtState.Text = frm.cboState.Text¶
PutDataIntoDocument frm, doc¶
End If¶
Unload frm¶
If doc.Bookmarks.Exists("txtStartBody") Then¶
End If¶
End Sub¶
' * * * * *¶
Sub GetDataFromDocument(frm As UserForm, doc As Word.Document)¶
'Variable declaration¶
Dim ctl As MSForms.Control¶
Dim firstControl As Boolean¶
For Each ctl In frm.Controls¶
If doc.Bookmarks.Exists(ctl.Name) Then¶
ctl.Text = doc.Bookmarks(ctl.Name).Range.Text¶
If Not firstControl Then¶
ctl.SelStart = 0¶
ctl.SelLength = Len(ctl.Text)¶
firstControl = True¶
Search JabSto ::

Custom Search