Microsoft Office Tutorials and References
In Depth Information
Entering Data Easily Using a Custom Dialog Box
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 form
should be inserted (select the location, then Insert | Bookmark). The
bookmark names should match the names of the text boxes in the
UserForm. Some of the text boxes used in the example are txtRecipient,
txtStreetAddress, and txtCity.
4. To see and change the text box names in the Visual Basic Editor (VBE),
click on a text box and then look at the Name information in the
Properties window (it is usually the first entry listed). Type the correct
name in the box if changes need to be made.
Search JabSto ::

Custom Search