JPG
03-11-2020, 09:47 AM
I need to markup topics with tags. It works ok for an inline word but a single word followed by a return gives this tag
before
Creation
after selection of word and macro run
<link>Creation
</link>Creation
I want it to be in one line and no space after the word creation, in between the tags
<link>Creation</link>Creation
Private Sub CommandButton7LinkTopicsMarkup_Click()
InSelection = False
If selection.Type = wdSelectionIP Then InSelection = True
If InSelection = True Then
MsgBox ("select some text")
Exit Sub
End If
'remove any spaces after word
While selection.Characters.Last = " "
If selection.Characters.Last = " " Then
selection.MoveEnd Unit:=wdCharacter, Count:=-1
End If
Wend
Dim textOriginal As selection
Set textOriginal = selection
With selection.Range
.InsertBefore "<link>" & textOriginal & "</link>"
End With
End Sub
I was just trying to figure a way and came up with this to modify the code in red. It works. However is there a proper way to deal with this?
While selection.Characters.Last = " " Or selection.Characters.Last = Chr(13)
If selection.Characters.Last = " " Then
selection.MoveEnd Unit:=wdCharacter, Count:=-1
End If
If selection.Characters.Last = Chr(13) Then
selection.MoveEnd Unit:=wdCharacter, Count:=-1
End If
Wend
before
Creation
after selection of word and macro run
<link>Creation
</link>Creation
I want it to be in one line and no space after the word creation, in between the tags
<link>Creation</link>Creation
Private Sub CommandButton7LinkTopicsMarkup_Click()
InSelection = False
If selection.Type = wdSelectionIP Then InSelection = True
If InSelection = True Then
MsgBox ("select some text")
Exit Sub
End If
'remove any spaces after word
While selection.Characters.Last = " "
If selection.Characters.Last = " " Then
selection.MoveEnd Unit:=wdCharacter, Count:=-1
End If
Wend
Dim textOriginal As selection
Set textOriginal = selection
With selection.Range
.InsertBefore "<link>" & textOriginal & "</link>"
End With
End Sub
I was just trying to figure a way and came up with this to modify the code in red. It works. However is there a proper way to deal with this?
While selection.Characters.Last = " " Or selection.Characters.Last = Chr(13)
If selection.Characters.Last = " " Then
selection.MoveEnd Unit:=wdCharacter, Count:=-1
End If
If selection.Characters.Last = Chr(13) Then
selection.MoveEnd Unit:=wdCharacter, Count:=-1
End If
Wend