2011-07-23 25 views
1

我使用Microsoft.Office.Interop.PowerPoint從* .pptx演示文稿中替換每個幻燈片中的某個特定標記。替換PowerPoint中的一些文本

問題是,令牌所在的文本框中有不同格式的行(例如具有不同字體大小的行)。

我真的試圖通過這兩個

shape.TextFrame.TextRange.Text = strStartText + replacementString + strEndText;

shape.TextFrame.TextRange.Text = 
    shape.TextFrame.TextRange.Text.Replace(oldString, replacementString); 

做替換,但它統一,從而破壞我的文本框的所有格式。 所有行和單詞現在具有相同的尺寸/顏色等。

有沒有解決方法?

回答

2

PowerPoint的.TextRange對象有一個與VB/VBA的Replace命令類似的.Replace方法,但它保留了格式。

例如,假設你有變量奧什形狀的參考:

With oSh 
    With .TextFrame.TextRange 
     .Replace findwhat:=oldString, replacewhat:= replacementString 
    End With 
End With 
+0

謝謝!抱歉,offtop,但是你在這裏使用的語法是什麼? – wh1t3cat1k

+0

VBA。對不起,忘了提及你必須翻譯成.NETness,沿着... = shape.TextFrame.TextRange.Replace(oldString,replacementString);在這種情況下,TextRange.Replace是一種方法;它直接替換對象,不像.Text.Replace,它會返回一個字符串,但不會影響.TextRange.Text –

+0

在PowerPoint中爲我工作 – Cocowalla