PDA

View Full Version : VBA Word Help



jayasreer
08-26-2013, 10:06 PM
Hi,

I want to Apply para tag for the selected lines in command button, but its not working. Let me know if any additional codes need to add.



[Private Sub CommandButton1_Click()
With Selection
Selection.InsertBefore "<para>"
Selection.MoveRight wdCharacter, -1, wdExtend
Selection.InsertAfter "</para>"
End With
Selection.EndKey
Call Module1.QA
End Sub

code formatting and tags added by SamT

fumei
08-28-2013, 11:25 PM
"its not working." is not helpful to post. When you have a problem please state what it is...exactly.

Also, using Selection can be tricky doing this. Does the selection cover the whole paragraph, or just part of it? More importantly, does it include the paragraph mark. IF the Selection does NOT include the paragraph mark, As a starting point you could try:

Sub AddParaTags()
Dim r As Range
Set r = Selection.Range
With r
.InsertBefore "<para>"
.Collapse 0
.InsertAfter "</para>"
End With
End Sub