Word文書の最初のページからすべての先頭の空白(スペース、空の行)を削除するにはどうすればよいですか?
質問する
3227 次
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
于 2013-03-25T00:19:56.497 に答える