Yes, thank you. Now we have something to actually work with.
1. You can make your code a bit more efficient with the checking if the bookmarks exist, then getting the Range.Text. Use an array.
Code:
Dim BMArray(5) As String
Dim BMText(5) As String
Dim var
BMArray(0) = "Kund"
BMArray(1) = "Kontakt"
BMArray(2) = "Datum"
BMArray(3) = "Projektnamn"
BMArray(4) = "Ansvarig"
BMArray(5) = "Rubrik"
For var = 0 To UBound(BMArray())
If ActiveDocument.Bookmarks.Exists(BMArray(var)) = True Then
BMText(var) = ActiveDocument.Bookmarks(BMArray(var)).Range.Text
Next
Me.txtCustomer = BMText(0)
Me.txtContact = BMText(1)
Me.txtHeader = BMText(2)
Me.txtDate = BMText(3)
Me.txtProject = BMText(5)
Me.txtResponsible = BMText(5)
uses an array of the bookmarks to check if each exists, and if it does, fill a matching array of the text. You don't need to do separate IF statements.
2. You do not say, but it LOOKS like you want to do your text insertion at
Code:
If ActiveDocument.Bookmarks.Exists("Start") = True Then
Selection.GoTo What:=wdGoToBookmark, Name:="Start"
End If
You really should comment that. I can only guess that it where you want to do the text insertion, because you are using the Selection - see following.
3. The code
Code:
Selection.InsertAfter "Projectname"
Selection.Style = ActiveDocument.Styles("Header 1")
Selection.InsertAfter vbCrLf
Selection.Style = ActiveDocument.Styles("Normal")
Selection.InsertAfter vbCrLf
Selection.Style = ActiveDocument.Styles("Normal")
Selection.InsertAfter "Projectdesctiption"
Selection.Style = ActiveDocument.Styles("Header 3")
is backwards. You make the Selection style whatever you want, THEN put the text. Let's look at it.
Projectname - paragraph 1 (uses the first vbcrlf)
blank paragraph - paragraph 2 (uses the second vbcrlf)
Projectdesctiption - paragraph 3
Again, you don't say, but if you ARE, or CAN, use the bookmark Start itself, then
Code:
Dim strTextInsert As String
Dim r As Word.Range
[COLOR=red]' your string[/color red]
strTextInsert = "Projectname" & vbCrLf & vbCrLf & _
"Projectdesctiption"
UpdateBookmark "Start", strTextInsert
Set r = ActiveDocument.Bookmarks("Start").Range
r.Paragraphs(1).Range.Style = "Heading 3"
r.Paragraphs(3).Range.Style = "Heading 3"
Set r = Nothing
There are other ways...but you are not fully clear on where the text is to be inserted, and it may change depending on that.
Hope this helps.
Gerry
My paintings and sculpture