Microsoft Office Tutorials and References
In Depth Information
Filling a Word Combo Box with Data from Excel
'The user didn't select any text; a bookmark without¶
'content will be inserted with¶
'an incremented name txt#¶
'Calculate that name¶
BookmarkName = "txt" & var.Value¶
var.Value = CStr(CLng(var.Value) + 1)¶
'Alternately, a prompt can be displayed¶
'to ask the user for the name¶
'Uncomment the next two lines to use that method¶
'BookmarkName = InputBox( _¶
'No text is selected. Type in a bookmark name.")¶
Else¶
'Get the bookmark name based on the selected text¶
BookmarkName = ProcessBookmarkName(rng.Text)¶
End If¶
'Check if the bookmark name already exists;¶
'if it does it will be incremented with a counter¶
BookmarkName = "txt" & CheckIfDuplicateName( _¶
ActiveDocument, BookmarkName)¶
'Insert the bookmark¶
ActiveDocument.Bookmarks.Add _¶
Name:=BookmarkName, Range:=rng¶
End Sub¶
' * * * * *¶
Function ProcessBookmarkName(s As String) As String¶
'Variable declaration¶
Dim i As Long¶
'Maximum length of a bookmark name is 40 characters¶
'Because txt will be added to the beginning¶
'therefore cut off at 37¶
If Len(s) > 37 Then s = Left(s, 37)¶
'Replace all spaces with underline characters¶
s = Replace(s, " ", "_")¶
'Remove any numbers at the beginning¶
Do While IsNumeric(Left(s, 1)) = True¶
s = Mid(s, 2)¶
Debug.Print s¶
Loop¶
'Remove invalid characters¶
'(following list is not comprehensive)¶
For i = 1 To Len(s)¶
Select Case Mid(s, i, 1)¶
Case "§", "°", "+", "¦", "@", Chr$(34), "*", _¶
"#", "%", "&", "", "/", "|", "(", "¢", ")", _¶
"=", "?", "'", "´", "^", "`", "~", "[", "]", _¶
"¨", "!", "{", "}", "$", "£", "<", ">", "<", _¶
".", ",", ":", ";", "-"¶
s = Left(s, i - 1) & Mid(s, i + 1)¶
Case Else¶
Cmb
Search JabSto ::




Custom Search