
two questions on how to get data entries in userforms into bookmarks (if possible at all)
Hi Ben,
Quote:
> 1.
> I have created a VBA Userform with a listbox, an up and a down arrow, and
> an OK and a Cancel button.
> Using Userform_Initialize I load the listbox with a number of items, let's
> say: Amsterdam, Berlin, London.
> After using the up and down arrow they appear in a different order;
Berlin,
> London, Amsterdam.
> Is it possible without selecting any item to export this list to a Word
> document in such a way that every item from the listbox is assigned to a
> separate bookmark.
So you want to use every item from the listbox to a bookmark, no matter what
the user chooses but in the order they are appearing in the listbox itself?
In the following code I assume that there are exactly the same number of
bookmarks in the document (Bookmark1, Bookmark2 and Bookmark3 etc) as the
number of items in the listbox:
------------------------------------------------------------------------
Dim i As Integer
Dim sNameBookmark As String
For i = 1 To ListBox1.ListCount
sNameBookmark = "Bookmark" & i
ActiveDocument.Bookmarks(sNameBookmark).Range.Text = _
ListBox1.List(i - 1)
Next i
------------------------------------------------------------------------
Quote:
> 2. Second question:
> How does one export entries, from textboxes in a multi-page form, into
> bookmarks that appear in a Word document?!
Same way as in a normal form:
------------------------------------------------------------------------
Dim oRange As Range
'Check to see if the bookmark is there
If ActiveDocument.Bookmarks.Exists("Bookmark1") Then
Set oRange = ActiveDocument.Bookmarks("Bookmark1").Range
oRange.Text = TextBox1.Text
'The bookmark is gone now, so you need to add it again
ActiveDocument.Bookmarks.Add name:="Bookmark1", Range:=oRange
End If
Set oRange = Nothing
------------------------------------------------------------------------
Hope this helps,
regards,
Astrid
For direct access to all Microsoft newsgroups: