View Single Post
 
Old 04-21-2025, 03:40 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
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

It is not clear what your macro is actually doing. What is contained originally in the bookmarked ranges 'Husband' and 'Wife'?
If the aim is to simply transpose the contents of the two bookmarked ranges then the following will do that:
Code:
Sub WillGenderChange21April()
Dim sHusband As String, sWife As String
    If ActiveDocument.Bookmarks.Exists("Husband") = True Then
        sHusband = ActiveDocument.Bookmarks("Husband").Range.Text
    End If
    If ActiveDocument.Bookmarks.Exists("Wife") = True Then
        sWife = ActiveDocument.Bookmarks("Wife").Range.Text
    End If
    FillBM "Wife", sHusband
    FillBM "Husband", sWife
End Sub

Private Sub FillBM(strbmName As String, strValue As String)
'Graham Mayor - https://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        If .Bookmarks.Exists(strbmName) = True Then
            Set oRng = .Bookmarks(strbmName).Range
            oRng.Text = strValue
            oRng.Bookmarks.Add strbmName
        End If
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
If, however that is not the case, can you please indicate exactly what you have in the document (a sample would be nice) and what you intend to end up with.
__________________
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