Word) (Range.Delete 方法

刪除指定數目的字元或文字。

語法

運算式刪除 ([Unit], [Count])

需要 expression。 代表 Range 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Unit 選用 Variant 摺疊的範圍是要刪除的單位。 可以是 WdUnits 常數之一。
Count 選用 Variant 要刪除的單位數。 若要刪除此範圍之後的單位,請摺疊此範圍並使用正數。 若要刪除此範圍之前的單位,請摺疊此範圍並使用負數。

傳回值

Long

註解

此方法會傳回 Long 值,指出刪除的項目數或會傳回 0 (零) 如果刪除作業失敗。

範例

這則範例會選取並刪除使用中文件的內容。

Sub DeleteSelection() 
 Dim intResponse As Integer 
 
 intResponse = MsgBox("Are you sure you want to " & _ 
 "delete the contents of the document?", vbYesNo) 
 
 If intResponse = vbYes Then 
 ActiveDocument.Content.Select 
 Selection.Delete 
 End If 
End Sub

另請參閱

Range 物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應