Microsoft Office Tutorials and References
In Depth Information
Filling a Word Combo Box with Data from Excel
'Otherwise, do nothing¶
End Select¶
Next i¶
ProcessBookmarkName = s¶
End Function¶
' * * * * *¶
Function CheckIfDuplicateName(doc As Word.Document, _¶
BookmarkName As String) As String¶
'Variable declaration¶
Dim var As Word.Variable¶
If varExists(doc, varDuplicateName) = False Then¶
ActiveDocument.Variables.Add _¶
Name:=varDuplicateName, Value:="1"¶
End If¶
Set var = ActiveDocument.Variables(varDuplicateName)¶
If doc.Bookmarks.Exists(BookmarkName) Then¶
'Calculate incremented name¶
BookmarkName = Left(BookmarkName, _¶
Len(BookmarkName) - Len(var.Value)) & var.Value¶
var.Value = CStr(CLng(var.Value) + 1)¶
End If¶
CheckIfDuplicateName = BookmarkName¶
End Function¶
' * * * * *¶
Function varExists(doc As Word.Document, _¶
s As String) As Boolean¶
'Variable declaration¶
Dim var As Word.Variable¶
varExists = False¶
'Loop through the list of document variables¶
'and check whether it already exists by¶
'comparing the name¶
For Each var In doc.Variables¶
If var.Name = s Then¶
varExists = True¶
Exit For¶
End If¶
Next var¶
End Function¶
3. Create bookmarks in the template where the data items in the
UserForm should be inserted (select the location, then Insert |
Bookmark). The bookmark names should match the names of the text
boxes in the form. In the sample, some of these are: txtRecipient,
txtStreetAddress, and txtCity.
Cmb
Tip: See the Creating a Bookmark from a Selection entry on page 260 for a tool to quickly
create bookmarks from text selections.
Search JabSto ::




Custom Search