Macro xóa dòng trống trong MS Word

Liên hệ QC

nvson

Geotechnics
Thành viên danh dự
Tham gia
20/9/06
Bài viết
793
Được thích
1,285
Nghề nghiệp
ĐCTV - ĐCCT
Macro sau sẽ thực hiện việc xoá các dòng trống trong MS Word
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
(Sưu tầm)
 
Bác có thể hoàn thiện đoạn macro trên để đáp ứng các yêu cầu sau :

* Xóa bỏ các khoảng trắng giữa các từ khi cách quá xa.
* Khi xong một câu có dấu chấm ,thì sẻ viết hoa đầu câu .
* Khi xuống hàng ,biết thụt vô đầu dòng và viết hoa.
Lý do : khi tải một số bài từ trên mạng về ,thì hay gặp các lỗi ở trên
 
Web KT
Back
Top Bottom