共用方式為


PowerPoint) (TextRange 物件

含有附加至圖案的文字,及操作文字的屬性及方法。

註解

下列範例說明如何:

  • 傳回任何您指定之圖案中的文字範圍。

  • 傳回選取部分中的文字範圍。

  • 傳回文字範圍中的特殊字元、單字、字行、句子或段落。

  • 尋找及取代文字範圍中的文字。

  • 將文字、日期與時間或投影片編號插入文字範圍中。

  • 依本身需求在文字範圍中定位游標。

範例

使用TextRangeTextFrame 屬性 若要傳回之任何您指定的圖案的 TextRange 物件的物件。 使用 Text屬性可傳回 TextRange 物件中的文字字串。 下列範例會將矩形新增至 myDocument,並且設定內含的文字。

Set myDocument = ActivePresentation.Slides(1)

myDocument.Shapes.AddShape(msoShapeRectangle, 0, 0, 250, 140) _

    .TextFrame.TextRange.Text = "Here is some test text"

由於 Text 屬性是 TextRange 物件的預設屬性,下列兩個陳述式是相等。

ActivePresentation.Slides(1).Shapes(1).TextFrame _

    .TextRange.Text = "Here is some test text"

ActivePresentation.Slides(1).Shapes(1).TextFrame _

    .TextRange = "Here is some test text"

使用HasTextFrame若要判斷圖案是否有文字圖文框,並使用HasText屬性 若要判斷文字圖文框是否包含文字的屬性。

使用 Selection 物件的 TextRange 屬性來傳回目前選取的文字。 下列範例會將選取範圍複製到剪貼簿。

ActiveWindow.Selection.TextRange.Copy

使用其中一種方法來傳回 TextRange 物件的文字部分: 字元線條段落執行句子文字.

使用 [尋找] 和取代若要尋找及取代文字範圍內文字的方法。

使用其中一種方法可以將字元插入 TextRange 物件︰InsertAfterInsertBeforeInsertDateTimeInsertSlideNumberInsertSymbol.

方法

名稱
AddPeriods
ChangeCase
Characters
Copy
Cut
Delete
Find
InsertAfter
InsertBefore
InsertDateTime
InsertSlideNumber
InsertSymbol
LtrRun
Paragraphs
Paste
PasteSpecial
RemovePeriods
Replace
RotatedBounds
RtlRun
執行
Select
Sentences
TrimText
Words

屬性

名稱
ActionSettings
應用程式
BoundHeight
BoundLeft
BoundTop
BoundWidth
數目
Font
IndentLevel
LanguageID
長度
ParagraphFormat
Parent
Start
Text

另請參閱

PowerPoint 物件模型參考資料

支援和意見反應

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