it's Martin from Berlin (Germany - so please excuse my wrong English)...
I'm trying to edit EMF pastes in PPT using VBA. The EMF pastes are Excel charts and I used
ActiveWindow.Selection.SlideRange.Shapes.PasteSpecial DataType:=3 (enhanced metafile)
Without VBA it is easy: Just rightclick the image and "ungroup" (2x).
In VBA I tried the following:
1. Selecting the right shape (works), then
ActiveWindow.Selection.ShapeRange.Ungroup.Select
This runs on an error: "...cannot ungroup".
In another thread a "solution" was given: Recording a macro -> not possible in PPT 2007!
When I record a macro in PPT 2003, it says exactly the same:
ActiveWindow.Selection.ShapeRange.Ungroup.Select
but it doesn't work.
It seems that there should be one step before that converts the emf image into "office format" (if you do it without VBA after clicking "ungroup" a message box occurs that askes, if you want to convert the graphics into "office format").
Any idea what to do that ungroup is working with VBA?
This works here:
Sub UngroupPastedChart()
Dim oShRange As ShapeRange
Dim oSh As Shape
Set oShRange = ActiveWindow.Selection.SlideRange.Shapes.PasteSpecial(ppPasteEnhancedMetafile)
Set oShRange = oShRange.Ungroup
Set oShRange = oShRange.Ungroup
End Sub
and add oShRange.Select if you want the ungrouped shapes to be selected at the end.
Related
So after a bit of digging I got some help to find a code to export a chart from Excel to Powerpoint, problem is it is only selecting an object.
Sub ertert()
With New PowerPoint.Application
With .Presentations.Add
With .Slides.Add(1, 12)
ActiveSheet.ChartObjects(1).CopyPicture xlPrinter, xlPicture
.Shapes.Paste
.Shapes(1).Select
.Application.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
.Application.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
End With
End With
End With
End Sub
the object it's selecting is a chart/vlookup image result inside of a larger chart (the object itself is named) so basically it's only getting a small part of the item itself.
Question is where I went wrong in having it only select an item? Also I would like to know how to modify this code to add to an existing Powerpoint (assuming the existing one is already open).
What exactly are you trying to do?
If you are just looking to display a chart that updates based on the content of your excel workbook you can simply copy the chart across and it creates a link between the two. When both your presentation and workbook are open it will update the chart automatically with no need for VBA.
I have a PowerPoint presentation with several Excel charts pasted as links. Using VBA, I have checked, and the type of these shapes is msoLinkedOLEObject.
Knowing this, I would like to first open the Excel file that contains the original chart through VBA and then use the "update link" command of the chart, like this:
I wish to open the workbooks first because using the "update link" command with an open Excel file is usually faster for me than just using the "update link" command directly (maybe because some PowerPoint presentations and some workbooks are really extense).
For the sld.Shapes(i).LinkFormat part of the code, I can use .UpdateLinks to directly refresh the data, but I cannot find any way to directly open the Excel source file (in the same way I can by manually clicking the linked chart).
Could this be achieved?
Sub UpdateExcelLinkedCharts()
Dim pres As Presentation
Dim sld As Slide
Dim shp As Shape
Set pres = Application.ActivePresentation
'Loop through all active slides in the presentation
For Each sld In pres.Slides
If sld.SlideShowTransition.Hidden = msoFalse Then
'If the slide is a msoLinkedOLEObject, proceed to update its link
For i = 1 To sld.Shapes.Count
If sld.Shapes(i).Type = 10 Then
sld.Shapes(i).LinkFormat.UpdateLinks
End If
Next i
End If
Next sld
MsgBox ("All Links Updated!")
End Sub
You can either use
sld.Shapes(i).OLEFormat.Activate
Or
sld.Shapes(i).OLEFormat.DoVerb
followed by sld.Shapes(i).LinkFormat.Update
Both will open the linked object so you can edit it. But notice that this is not enough to have a reference to an Excel Object that you can manipulate through VBA.
I want to be able to create a macro that will start text-to-speech on the text that is in the presenters notes. I will be applying the macro to a ActiveX button that will allow the user to start the reading and eventaully I would like to time the animations of the slides to the speech.
I have sucess in Excel VBA in being able to write out the command to speak a cell with:
application.speech.speak (sheet1.cells(1,1))
and I found a code that will enter text into the speaker notes section for all slides.
Sub AddTextAllSpeakerNotes()
Dim sld As Slide
For Each sld In ActivePresentation.Slides
sld.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange = ""
Next sld
End Sub
I have added the Microsoft Speech Object Library reference, but I can never get the VBA to recognize the speech commands and auto-complete any commands that will help me figure out how to get any further.
How can I write a code that will apply the text-to-speech command to the speaker notes section of a particular slide.
As commented, you can try this:
Dim XL As Excel.Application
Set XL = New Excel.Application
XL.Speech.Speak "I was able to make power point speak"
Provided you added reference to:
Microsoft Excel XX.X Object Library
Once you've bound Excel to PowerPoint, you can directly use its methods from there. In above code, you can simply replace the argument with the actual PPT object that contains the string you want spoken. HTH.
I'm writing a PowerPoint macro that opens a Word document and imports every picture in the document to its own slide. Because I can't place the Word InlineShape objects directly in PowerPoint, apparently, I'm using the clipboard. The relevant code is:
Dim wdApp As Object
Dim SourceDoc As Document
Dim TargetSlide As Slide
Dim Figures As Word.InlineShapes
Dim Figure As Word.InlineShape
Dim TargetShapeRange As ShapeRange
Set wdApp = CreateObject("Word.Application")
Set SourceDoc = wdApp.Documents.Open(FileName:=PathToFile, ReadOnly:=True)
Set Figures = SourceDoc.InlineShapes
For Each Figure In Figures
Figure.Range.Select
Figure.Application.Selection.Copy
Set TargetSlide = ActivePresentation.Slides.AddSlide(ActivePresentation.Slides.Count + 1, _
ActivePresentation.SlideMaster.CustomLayouts(6))
Set TargetShapeRange = TargetSlide.Shapes.Paste
Next Figure
With PowerPoint 2010 and Word 2010, this works perfectly. In PowerPoint 2013 (with Word 2013 installed, and referencing the Microsoft Word 15.0 Object Library rather than 14.0), the Set TargetShapeRange = TargetSlide.Shapes.Paste line gives me run-time error '-2147188160 (80048240)':
Shapes (unknown member): Invalid request. Clipboard is empty or contains data which may not be pasted here.
I've tried using the Copy and CopyAsPicture methods on both the Selection and Range objects. I've tried using the Shapes.PasteSpecial command. I've tried several different ways of accessing the Word Application object. Nothing works.
Notably, if I modify the code to copy the preceding paragraph of text in addition to the picture, the script works—it retrieves the text, but not the picture.
I know this question is almost two years old but I found this through google after having a similar issue so I'll post this here.
Try
Figure.Application.ActiveWindow.ScrollIntoView Selection.Range, True
right before copying. It works for me even with screenupdating disabled or if the application is not visible.
I have a excel file in which 3 Powerpoint presentations are embedded(as object). These are the blank templates of the deck I want to prepare. How can I assign these embedded Powerpoint presentations through VBA. I know that I can keep Powerpoint presentations separately and access them but I want to make them into one file this time. Thanks in advance
OK, assuming you have a PPT presentation embedded in Excel and its name is "Object 1"
Dim oSh As Shape
Set oSh = ActiveSheet.Shapes("Object 1")
With oSh
' Uncomment the appropriate line for the result you want
' Show
'.OLEFormat.Verb (1)
' Edit (in place)
'.OLEFormat.Verb (2)
' Open
.OLEFormat.Verb (3)
End With