2014-05-06 41 views
0

我试图用vba复制Powerpoint中的值从一个表复制到另一个表。该文本涉及日期后的上标“st”,“nd”,“rd”等。我的代码是:保留通过vba输入数据的文本格式

slide3.Shapes(9).Table.Cell(1, 1).Shape.TextFrame.TextRange = slide3.Shapes(2).Table.Cell(1, 1).Shape.TextFrame.TextRange 

这些值可以很好地传输,但“st”,“nd”...与其余字符的格式相同。

我希望复制上标格式。

+0

我知道这如果您在TextRange的迭代人物来完成,并应用所需的源格式的方式。但我不确定这可以通过其他方式完成。 –

回答

1

不确定这是否可以在没有字符迭代的情况下完成,但我知道这可以通过这种方式完成。创建一个接受两个TextRange对象作为参数的子例程,然后您可以迭代每个字符。

调用它想:

CopyTextFormats slide3.Shapes(9).Table.Cell(1, 1).Shape.TextFrame.TextRange, _ 
        slide3.Shapes(2).Table.Cell(1, 1).Shape.TextFrame.TextRange 

这里是子程序:

Sub CopyTextFormats(tRange1 As TextRange, tRange2 As TextRange) 
Dim i As Long 

'## "copy" the plain text from one table cell to the other 
tRange2 = tRange1 

'## Iterate the characters, in order to "copy" specific formatting properties: 
For i = 1 To tRange1.Characters.Count 

tRange2.Characters(i, 1).Font.Superscript = tRange1.Characters(i, 1).Font.Superscript 
'### You can use this for other properties that you want to copy, too: 
' 
'tRange2.Characters(i, 1).Font.Bold = tRange1.Characters(i, 1).Font.Bold 
'tRange2.Characters(i, 1).Font.Underline = tRange1.Characters(i, 1).Font.Underline 
' 
'If you don't want to copy a property, just omit it from this function 

Next 

End Sub