none
Paste Picture in Powerpoint using VB RRS feed

  • Question

  • I am using VB to copy a group of drawing objects from Excel and pasting into Powerpoint.  It works fine if there are less than 4000 ovals in the group of objects.  If there are more than 4000 ovals, I get an error.  I can determine whether there are more than 4000 ovals, and do something different in that case.   When I do the following manually, it works:

    1. In Excel, select the object group.  Choose Copy.

    2. In Powerpoint, choose Paste | Picture (U).

    The question is, how do I do this in VB?  The documentation doesn't describe this option, I haven't found the answer in any online forums, and I can't record a macro in Powerpoint.  Or is there some other way to paste over 4000 ovals?

    Any suggestions are greatly appreciated.

    Tuesday, May 14, 2013 5:02 PM

Answers

  • Quist,

    Thank you for your detailed suggestions.  I tried a lot of things, including using the clipboard, and finally got it to work by using the suggestions found here.

    http://www.ozgrid.com/forum/showthread.php?t=177423

    Tuesday, May 21, 2013 1:31 PM

All replies

  • You can do this maybe with the Clipboard?

    I'm doing something the same but with C#/.NET

    In Excel, I simply select the image and save it to Clipboard, which I save in a file.

    item.SheetObject.CopyBitmapToClipboard();
    Image img;
    //save it in a file
    img = Clipboard.GetImage();
    img.Save(temporaryFilePath + ".bmp", ImageFormat.Bmp);

    And in Powerpoint, I select the current slide where to paste it and add the picture.

    slide.Select();
    slide.Shapes.AddPicture(temporaryFilePath + ".bmp", MsoTriState.msoTrue, MsoTriState.msoTrue, pptleft, ppttop, pptwidth, pptheight);
    pptshape.Delete();

    Of course, you need to define where exactly you want to replace it, that's why you have the parameters in AddPicture.

    If you want to identify now different pictures in Excel and Powerpoint, you can work with the shape and use AlternativeText of the shape, where you can store information for future, in case you plan to do those replacement more often, you save an information in that AlternativeText

    shape.AlternativeText = <some text>;

    Later in your code, you can check it faster.

    if (pptshape.AlternativeText.Contains("<some pattern>"))

     For VB:

    For Each pptSlide In pptPres.Slides
    	pptSlide.Select
    	For Each pptShape In pptSlide.Shapes
    	    If pptShape.Type = 17 Then 'msoTextBox
    		if InStr(pptShape.Tags("some tag"), "!") > 0 Then
    			shapeData = Split(pptShape.Tags("some tag"), "!")
    			<Replace your picture>
    		End If
    	     End If
            Next
    Next

    If you don't seem to find something for VB, just look it up for C#, it will be similar.

    Set excelApp = CreateObject("excel.application")
    Set excelWrkbook = excelApp.WorkBooks.Add
    Set excelSheet = excelWrkbook.WorkSheets(1)
    ActiveDocument.GetSheetObject(tableName).CopyTableToClipboard true
    excelSheet.Cells(1,1).Select
    excelApp.Selection.Copy
    pptSlide.Shapes.PasteSpecial (10) 'OLE Object
    Hope it might help you.
    Wednesday, May 15, 2013 11:57 AM
  • Quist,

    Thank you for your detailed suggestions.  I tried a lot of things, including using the clipboard, and finally got it to work by using the suggestions found here.

    http://www.ozgrid.com/forum/showthread.php?t=177423

    Tuesday, May 21, 2013 1:31 PM