R
Robert
Hello,
I'm trying to create a template which will start with a userform where you
can fill in some data which will be added to bookmarks in a secure section
of the form.
The problem i am facing is as follows:
The adress is a multiline textbox in the userform, the lenght of this field
varies, because the user is allowed to change the adress using the userform.
The text from the textbox most be inserted into a bookmark which is placed
into a table. When the adress is placed in the bookmark i change the range
of that bookmark so i have always the correct lenght od the bookmark so that
i can select i easily again. When i want to change the adress the selection
is still extended whith 2 places which results that a linefeed (chr(10)) and
sometimes a enter(chr(13)) is selected. As a result of that selection the
bookmarks exseets the table, which as a result is deleted the next time the
adress is changed. I have added the code i used for filling and changing of
the userform fields and bookmarks.
I hope someone understands my problem and that i have writed this article
correctly while English isn't my native language
Thanks in advance
Robert
Code for filling and changing the bookmarks
Private Sub KnAkkoord_Click()
Dim Ctrl As Control, start As Long, Hdoc As ThisDocument
Set Hdoc = ThisDocument
For Each Ctrl In FrmAdressering.Controls
If Not (Ctrl.Tag = "") And Hdoc.Bookmarks.Exists(Ctrl.Tag) Then
With Hdoc.Bookmarks
.Item(Ctrl.Tag).Select
start = Selection.start
Selection.Delete
.Add (Ctrl.Tag)
.Item(Ctrl.Tag).Range.Text = Ctrl.Value
.Add Ctrl.Tag, Hdoc.Range(start, start + Len(Ctrl.Value))
End With
End If
Next Ctrl
Unload FrmAdressering
End Sub
Code for putting in the values from the bookmarks into the form
Dim Hdoc As ThisDocument, BM As Bookmark, Frm As FrmAdressering
Set Hdoc = ThisDocument
Load FrmAdressering
Set Frm = FrmAdressering
For Each BM In Hdoc.Bookmarks
BM.Select
Frm.Controls.Item(BM.Name).Value = BM.Range.Text
Next BM
FrmAdressering.Show
End Sub
I'm trying to create a template which will start with a userform where you
can fill in some data which will be added to bookmarks in a secure section
of the form.
The problem i am facing is as follows:
The adress is a multiline textbox in the userform, the lenght of this field
varies, because the user is allowed to change the adress using the userform.
The text from the textbox most be inserted into a bookmark which is placed
into a table. When the adress is placed in the bookmark i change the range
of that bookmark so i have always the correct lenght od the bookmark so that
i can select i easily again. When i want to change the adress the selection
is still extended whith 2 places which results that a linefeed (chr(10)) and
sometimes a enter(chr(13)) is selected. As a result of that selection the
bookmarks exseets the table, which as a result is deleted the next time the
adress is changed. I have added the code i used for filling and changing of
the userform fields and bookmarks.
I hope someone understands my problem and that i have writed this article
correctly while English isn't my native language
Thanks in advance
Robert
Code for filling and changing the bookmarks
Private Sub KnAkkoord_Click()
Dim Ctrl As Control, start As Long, Hdoc As ThisDocument
Set Hdoc = ThisDocument
For Each Ctrl In FrmAdressering.Controls
If Not (Ctrl.Tag = "") And Hdoc.Bookmarks.Exists(Ctrl.Tag) Then
With Hdoc.Bookmarks
.Item(Ctrl.Tag).Select
start = Selection.start
Selection.Delete
.Add (Ctrl.Tag)
.Item(Ctrl.Tag).Range.Text = Ctrl.Value
.Add Ctrl.Tag, Hdoc.Range(start, start + Len(Ctrl.Value))
End With
End If
Next Ctrl
Unload FrmAdressering
End Sub
Code for putting in the values from the bookmarks into the form
Dim Hdoc As ThisDocument, BM As Bookmark, Frm As FrmAdressering
Set Hdoc = ThisDocument
Load FrmAdressering
Set Frm = FrmAdressering
For Each BM In Hdoc.Bookmarks
BM.Select
Frm.Controls.Item(BM.Name).Value = BM.Range.Text
Next BM
FrmAdressering.Show
End Sub