PowerPoint VBA Error - Paste Special (Enhanced Metafile)

I use a macro in PowerPoint 2003 SP3 to find the specified chart in an Excel workbook, copy it, and then paste into the current slide as an extended metafile, ultimately the following line of code:

Application.ActiveWindow.View.PasteSpecial DataType:=ppPasteEnhancedMetafile 

Once it works, I also get the following error:

  Run-time error '-2147188160 (80048240)':
 View (unknown member): Invalid request.  The specified data type is unavailable. 

If I end the macro and try to manually insert Special as an extended metafile, I have no problem, so it is not as if the clipboard object or paste type is invalid.

Has anyone else experienced this? Do you have a solution or workaround? There are several results in this error and no solutions in a Google search.


Update

The general code is as follows:

 Set presPPTCurrent = ActivePresentation Set objXLApp = GetObject(, "Excel.Application") ''#Find the target chart and copy it to the clipboard With objXLApp ''#This part works - if I go to Excel, I can see that the chart is copied End With ''#Now paste in the chart as an Enhanced Metafile presPPTCurrent.Application.Activate Application.ActiveWindow.View.PasteSpecial DataType:=ppPasteEnhancedMetafile 

Note that this is in Sub, to which the Shape is transmitted (the transmitted form is used as a link to search for a chart in Excel). I realized that these are only errors when I try to reuse this sub on several forms submitted from the For Next loop to another Sub.

However, if I pass one Shape to this Sub using another Sub, and then re-run the Sub, which passes multiple Shapes, it works fine.


Decision

According to Otaku, the macro was losing its focus on the slide panel. Informing that the problem was solved for re-selecting the slide area.

 Application.ActiveWindow.Panes(2).Activate 
+4
source share
5 answers

The likelihood of losing focus when switching between Excel and PowerPoint results in a loss of PowerPoint focus and, therefore, PowerPoint does not require ActiveWindow to insert, or ActiveWindow becomes another Pane in PowerPoint, such as Slide Sorter or Notes panel.

+3
source

Here is a macro that works correctly and costs only one click instead of 3 to insert text without formatting.

 Sub PasteTxt() 'Michel Mahieu - 2013.01.30 - Edit, Paste Special, Text whithout formatting ActiveWindow.View.PasteSpecial ppPasteText End Sub 

I also have 3 macros to put the text in the form in one click instead of 4: - The format of the automatic form - Text area - Select the top, middle, bottom, - Click on the desired location

Here is the top macro:

 Sub Haut() 'Michel Mahieu - 2013.01.30 - Text on top With ActiveWindow.Selection.ShapeRange.TextFrame .VerticalAnchor = msoAnchorTop End With ActiveWindow.Selection.ShapeRange.Fill.Transparency = 0# End Sub 

Enjoy, Michel.Mahieu@Cassidian.com

+1
source

I had the same problem. I have a macro that exports many graphs to PowerPoint. But some actions for copy-paste end with the same error as above (Runtime error "-2147188160 (80048240)" :)

I realized that the PasteSpecial error did not occur due to loss of focus, but because of the loss of the clipboard.

Thus, the solution again returns the area to the clipboard, for example:

 On Error GoTo paste_error ppSlide.Shapes.PasteSpecial(2, link:=RangeLink).Select ... paste_error: Worksheets(SheetName).Range(RangeName).copy Resume 

Maybe this will help someone ...

+1
source

I was getting the same errors and experimenting with many solutions here. What ultimately worked for me was something very simple. I think this works because of the first line, which saves the link to the slide. The paste parameter may be EnhancedMetaFile instead of Bitmap.

  Sub Macro() Set sld = Application.ActiveWindow.View.Slide With GetObject(, "Excel.Application") .Workbooks(1).Sheets(1).Shapes(1).Copy End With sld.Shapes.PasteSpecial DataType:=ppPasteBitmap End Sub 
0
source

Data Type: wdPasteEnhancedMetafile

For some reason, the macro recorder uses ppPasteEnhancedMetafile, which is incorrect.

-1
source

Source: https://habr.com/ru/post/1315861/


All Articles