Hi...

I'm new to VBA in Word and need a nudge in the right direction.
I've written a Word VBA Userform that adds bookmarks & sets their values on the fly with either an ASCII Chr(9) for a tab or CHr(13) for carriage return after each bookmark.
However, when I've used a carriage return for a new line it's start from the top in effect reversing the order I need it in.
I've attached a pdf with the code with a screenshot of the userform with the results to help explain the situation.
If anyone can help with the code it would be greatly appreciated.

Found the Solution... here is the code if anyone finds this userform useful for anything else.

Private Sub txtSuburb_Change()
txtSuburb.Text = UCase(txtSuburb.Text)
End Sub
Private Sub cmdREadd_Click()
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=("Office")
ActiveDocument.Bookmarks("Office").Select
Selection.TypeText Text:="<Insert logo here for " + Trim(txtREoffice.Text) + ">" & vbCrLf
End With
txtREoffice.SetFocus
End Sub
Private Sub cmdSUBadd_Click()
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=("Suburb")
ActiveDocument.Bookmarks("Suburb").Select
Selection.TypeText Text:=Trim(txtSuburb.Text) + " * " & vbCrLf
End With
txtSuburb.SetFocus
End Sub
Private Sub cmdLISTadd_Click()
'Application.ScreenUpdating = False
Select Case cboValue.Value
Case "No Value"
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=("Value")
ActiveDocument.Bookmarks("Value").Select
Selection.TypeText Text:="<->" & Chr(9)
End With
Case "< 400K"
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=("Value")
ActiveDocument.Bookmarks("Value").Select
Selection.TypeText Text:="<R>" & Chr(9)
End With
Case "400K > < 700K"
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=("Value")
ActiveDocument.Bookmarks("Value").Select
Selection.TypeText Text:="<G>" & Chr(9)
End With
Case "700K > < 1M"
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=("Value")
ActiveDocument.Bookmarks("Value").Select
Selection.TypeText Text:="<K>" & Chr(9)
End With
Case "> 1M"
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=("Value")
ActiveDocument.Bookmarks("Value").Select
Selection.TypeText Text:="<B>" & Chr(9)
End With
End Select
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=("Address")
ActiveDocument.Bookmarks("Address").Select
Selection.TypeText Text:=Trim(txtAddress.Value) & Chr(9)
.Add Range:=Selection.Range, Name:=("Date_Time")
ActiveDocument.Bookmarks("Date_Time").Select
Selection.TypeText Text:=Trim(txtDateTime.Value) & Chr(9)
.Add Range:=Selection.Range, Name:=("Agent")
ActiveDocument.Bookmarks("Agent").Select
Selection.TypeText Text:=Trim(txtAgent.Value) & vbCrLf
End With
'Application.ScreenUpdating = False
cboValue.SetFocus
End Sub
Private Sub UserForm_Initialize()
txtREoffice.SetFocus
cboValue.Value = "Select"
With cboValue
.AddItem "No Value"
.AddItem "< 400K"
.AddItem "400K > < 700K"
.AddItem "700K > < 1M"
.AddItem "> 1M"
End With
End Sub
Private Sub cmdClose_Click()
Unload Me ' Close the form
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.