Hello all,
I would like to create a word document by copy-pasting the contents of several other documents to a bookmark.
After pasting, I would like to have the same bookmark available one line below the previously pasted content.
The program is working, but pastes every time at the beginning, so that the the content of my created word document is in reverse order:
I have tried to move the selection and create a new bookmark below the pasted content, but the only thing that worked is not very elegant:
Any hints, how a bookmark range can be moved?
I would like to create a word document by copy-pasting the contents of several other documents to a bookmark.
After pasting, I would like to have the same bookmark available one line below the previously pasted content.
The program is working, but pastes every time at the beginning, so that the the content of my created word document is in reverse order:
Code:
Sub Textmarke_fuellen_setzen(text_value As String, bookmark As String, objDoc As Object, objword As Object)
Dim BMRange As Object
objword.Activate
objword.Visible = True
If objDoc.bookmarks.Exists(bookmark) Then
Set BMRange = objDoc.bookmarks(bookmark).Range
BMRange.paste
End If
End Sub
I have tried to move the selection and create a new bookmark below the pasted content, but the only thing that worked is not very elegant:
Code:
Sub Textmarke_fuellen_setzen(text_value As String, bookmark As String, objDoc As Object, objword As Object)
Dim BMRange As Object
objword.Activate
objword.Visible = True
If objDoc.bookmarks.Exists(bookmark) Then
Set BMRange = objDoc.bookmarks(bookmark).Range
BMRange.InsertAfter (vbCrLf & vbCrLf & "aaa") 'aaa is used as a marker for the find-method
Set BMRange = Nothing 'get rid of selection
Set BMRange = objDoc.bookmarks(bookmark).Range 'set bookmark again
BMRange.Text = text_value
Set BMRange = objDoc.Content
BMRange.Find.Execute findtext:="aaa", Forward:=True 'bad way to get the selection to the right place for creating new bookmark
If BMRange.Find.Found = True Then
objDoc.bookmarks.Add bookmark, BMRange
End If
End Sub
Any hints, how a bookmark range can be moved?
Last edited: