View Single Post
 
Old 01-22-2015, 01:15 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

As suggested by 'Guessed', this is not the best way to achieve what you are trying to do here. It would be much better to use only one bookmark e.g. bkAddress and populate that bookmark with the results of your userform. Assign the values of the fields to strings as below, then assemble the strings as the finished address before filling the bookmark.

The FillBM code retains the bookmark so that you may run the userform again and change the content. Use it to fill any bookmark in your document:

Code:
Sub example()
Dim strAddress As String
Dim strName As String
Dim strBusiness As String
Dim strStreet As String
Dim strSuburb As String
Dim strState As String
Dim strPostCode As String
    strName = "Mr/Mrs Contact Name"
    strBusiness = ""        '"Business Name"
    strStreet = "Street Address"
    strSuburb = "Suburb"
    strState = "State"
    strPostCode = "Postcode"

    strAddress = strName & vbCr
    If Not strBusiness = "" Then strAddress = strAddress & strBusiness & vbCr
    strAddress = strAddress & strStreet & vbCr
    strAddress = strAddress & strSuburb & Chr(32) & _
                 strState & Chr(32) & strPostCode
    FillBM "bkAddress", strAddress
End Sub


Code:
Public Sub FillBM(strBMName As String, strValue As String)
Dim orng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set orng = .Bookmarks(strBMName).Range
        orng.Text = strValue
        orng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote