2013-03-22 3 views
2

Word 문서의 첫 페이지에서 선행 공백 (공백, 빈 줄)을 모두 제거하려면 어떻게합니까?Word 문서에서 선행 공백 제거

+1

아무 것도 시도하지 않으셨습니까? 초기 코드가 있습니까? –

답변

1

편집 : 내가 원했던 것은 문서의 처음부터 공백으로 만 구성된 모든 빈 단락이나 단락을 제거하는 것이 었습니다. 다음 매크로 DeleteLeadingWhitespace은이 작업을 수행하며 서식도 유지합니다.

' return True if the character at the given position is a whitespace character. 
' codepoints courtesy of http://en.wikipedia.org/wiki/Whitespace_character#Unicode 
Function IsSpace(ByVal Text As String, Optional ByVal Position As Long = 1) 

    Select Case AscW(Mid(Text, Position, 1)) 
     Case &H9, &HA, &HB, &HC, &HD, &H20, &H85, &HA0, _ 
       &H1680, &H180E, &H2000, &H2001, &H2002, &H2003, &H2004, &H2005, &H2006, _ 
       &H2007, &H2008, &H2009, &H200A, &H2028, &H2029, &H202F, &H205F, &H3000 
      IsSpace = True 

     Case Else 
      IsSpace = False 
    End Select 

End Function 

' return True if the paragraph consists only of whitespace 
Function IsParagraphEmpty(ByVal pg As Paragraph) 

    Dim i As Long 

    For i = 1 To Len(pg.Range.Text) 
     If Not IsSpace(pg.Range.Text, i) Then 
      IsParagraphEmpty = False 
      Exit Function 
     End If 
    Next 

    IsParagraphEmpty = True 
End Function 

' delete leading whitespace from the given document. 
Sub DeleteLeadingWhitespaceFrom(ByVal Document As Document) 

    While IsParagraphEmpty(Document.Paragraphs.First) 
     Dim i As Long 
     i = Document.Paragraphs.Count 

     Document.Paragraphs.First.Range.Delete 

     ' no change in number of paragraphs, bail 
     If i = Document.Paragraphs.Count Then Exit Sub 

    Wend 

End Sub 

' macro: delete leading whitespace from the active document 
Sub DeleteLeadingWhitespace() 

    DeleteLeadingWhitespaceFrom ActiveDocument 

End Sub