- Tham gia
- 20/9/06
- Bài viết
- 793
- Được thích
- 1,287
- Nghề nghiệp
- ĐCTV - ĐCCT
Macro sau sẽ thực hiện việc xoá các dòng trống trong MS Word
(Sưu tầm)
Mã:
Sub RemoveChars(TrimLines As Boolean, RemoveEmptyLines As Boolean)
Dim strList As Variant
ActiveDocument.Select
strList = Split(Selection, vbCr)
For Each varlist In strList
If TrimLines = True Then
If RemoveEmptyLines = False Then
finalstring = finalstring & Trim(varlist) & vbCr
Else
If varlist <> "" Then
finalstring = finalstring & Trim(varlist) & vbCr
End If
End If
Else
If RemoveEmptyLines = True Then
If varlist <> "" Then
finalstring = finalstring & varlist & vbCr
End If
Else
finalstring = finalstring & varlist & vbCr
End If
End If
Next
Selection = finalstring
With Selection
.EndKey Unit:=wdStory
.TypeBackspace
End With
End Sub
Public Sub Xoadong()
'Hay chon mot trong cac dong lenh sau:
'Remove Spaces and Empty Lines
Call RemoveChars(True, True)
'Remove Spaces but not Empty Lines
'Call RemoveChars(True, False)
'Remove Empty Lines but not Spaces
'Call RemoveChars(False, True)
'Does nothing
'Call RemoveChars(False, False)
End Sub