Pasting programmatically in Powerpoint??

C

Csabi

Hello,

I'm using .NET with powerpoint 2003 (anyway I want to use this app with PPT
2000 too!), with the autogenerated interop assemblies.

I want to paste RTF-format texts into Shapes in Powerpoint, here's my code
snippet:

System.Windows.Forms.DataObject dataObj = new
System.Windows.Forms.DataObject(System.Windows.Forms.DataFormats.Rtf,
bmwv.Value);
Clipboard.SetDataObject(dataObj, false);
try
{
//shape.TextFrame.TextRange.Paste();
shape.TextFrame.TextRange.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteRTF,
Microsoft.Office.Core.MsoTriState.msoFalse, "", 0, "",
Microsoft.Office.Core.MsoTriState.msoFalse);
}
catch(Exception ex)
{
string strMsg = ex.Message;
//shape.TextFrame.TextRange.Text = "";
}
dataObj = new DataObject(DataFormats.Text, "");
Clipboard.SetDataObject(dataObj, true);

Sorry if you can read hardly this snippet.

So, the bmwv.Value property contains the pasteable RTF-formatted text.

I tried with even PasteSpecial (as in the source above) and Paste()
functions, but always get the same error:

"TextRange (unknown member) : Invalid request. The specified data type is
unavailable."

Anyone maybe any solution? This problem drives me crazy... It'd be urgent :/

Bye,
Csabi
 
S

Shyam Pillai

Sorry, the PasteSpecial method wasn't available until PPT 2002 hence it will
not work in PowerPoint 2000.
 
C

Csabi

Hello,

Thanks, but anyway do you know any solution why do I get that error? Or some
workaround?

Thanks,
Bye,
Csabi
 
S

Shyam Pillai

The TextRange object does not support PasteSpecial in PPT 2000 hence the
error.
 
C

Csabi

Hi,

Ok, I understood that, but as I wrote in the first post, now just I'm
developing with PPT 2003 (not 2000), and there I get the error also (haven't
worked wiht PPT 2000 yet).

Bye,
Csabi
 
S

Shyam Pillai

Are you certain that the RTF format is available to paste into the
textrange?
I just ran some VB.Net code to test this out and you get the error message
only when RTF format isn't available on the clipboard.

Dim ppApp As New PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSld As PowerPoint.Slide

ppPres = ppApp.Presentations.Add
ppSld = ppPres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitle)
With ppSld.Shapes
.Item(1).TextFrame.TextRange.Text = "This is a test"
' Copy the text from the shape
.Item(1).TextFrame.TextRange.Copy()
' Paste RTF format into another shape. This works.
.Item(2).TextFrame.TextRange.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteRTF)
' Copy the shape itself.
.Item(2).Copy()
' Add another shape and try to copy into the textrange.
With
..AddLabel(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
0, 0, 100, 100)
'This will fail and give the error since RTF format is not available
on the clipboard.
.TextFrame.TextRange.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteRTF)
End With
End With

Regards,
Shyam Pillai
--
Handout Wizard: http://skp.mvps.org/how/


Csabi said:
Hi,

Ok, I understood that, but as I wrote in the first post, now just I'm
developing with PPT 2003 (not 2000), and there I get the error also
(haven't
worked wiht PPT 2000 yet).

Bye,
Csabi
 
Top