PDA

View Full Version : [SOLVED:] Delete Line Containing Bookmark



Hash86
09-23-2013, 12:02 AM
Hey everyone.
I'm very new with VBA, so hoping to get some help here..

10605
Here I have my bookmarks set.
I can enter in the details into the bookmarks just fine.

What I want, however, is for the second address bookmark (where the suburb goes) to be deleted and be replaced by the city and post code.

My code is this:

With ActiveDocument
' Set up the letter details
' Parent's name
.Bookmarks("Text1").Range.Text = TBP1Name
' Parent's address
.Bookmarks("Text2").Range.Text = TBP1Add1

If .Bookmarks("text3") = "" Then
.Bookmarks("text3").Delete
.Bookmarks("text4").Range.Text = TBCity + ", " + TBPostCode
Else
.FormFields("text3").Range.Text = TBSuburb
.FormFields("text4").Range.Text = TBCity + ", " + TBPostCode
End If
End With

where:
"Text1" = Parent's name
"Text 2" = Address line 1
"Text 3" = Address line 2
"Text 4" = City and Post code


What this comes up with is this:

Homer Simpson
742 Evergreen Terrace

Montana, 1234

But I want this:

Homer Simpson
742 Evergreen Terrace
Montana, 1234

Any help would be greatly appreciated! Thanks

Oh, while we're here, my form asks for "Parent's name" - both first and last name.
Any way of just putting the parent's first name only after the "Dear" in the first line of the letter?

Thanks in advance :)

gmaxey
09-23-2013, 06:34 AM
Your problem is that you are deleting the bookmark but not its parent paragraph.

.Bookmarks("Text3").Range.Paragraphs(1).Range.Delete

I'm assuming you are using a Userform for the getting the address data? Why aren't you using a single mulit-line text field?


Dim arrName() As String
arrName = Split(Parents Name, " ")
.Bookmarks("ParentsFirstName").Range.Text = arrName(0)

You would have to assume that the parent enters their first name first.

Hash86
09-23-2013, 10:59 PM
Your problem is that you are deleting the bookmark but not its parent paragraph.

.Bookmarks("Text3").Range.Paragraphs(1).Range.Delete

I'm assuming you are using a Userform for the getting the address data? Why aren't you using a single mulit-line text field?


Dim arrName() As String
arrName = Split(Parents Name, " ")
.Bookmarks("ParentsFirstName").Range.Text = arrName(0)

You would have to assume that the parent enters their first name first.


Thanks Greg.
The splitting of the parent's name works well.
The other part works as well.. Had to play with it, but got it sorted! Thanks!