PDA

View Full Version : [SOLVED:] VBA InlineShape vs Shape Objects and Sharing Between Word/PowerPoint



Duvdev
06-25-2014, 02:44 PM
Hello,

Not sure if I am attempting to do something that isn’t possible but I think I am a bit confused with the differences between InlineShapes and Shapes. I know that they can be converted but I am having issues with making the conversion on the copy.

To sum up what I am attempting to do is take a screenshot of a given application, run a Word macro to customize the screenshot then feed it over to PowerPoint to run a separate macro on the same screenshot. I can run the macros in either application with no issue but run into the issue when stringing them together.

After stepping through the macros it seems that my issue is related to the difference between InlineShapes and Shapes. I have been “anchoring” InlineShapes in Word then copy the shapes, force VBA to launch PowerPoint and finally edit the screenshots/move/etc. I have attempted to copy the screenshot that was operated on by Word, while that does appear to format the picture for PowerPoint I can no longer see it in Word. I also attempted to create two Objects (One As and InlineObject and the other as a Shape) and Set each object to the screenshot.

I have a feeling I am missing something small here, maybe when or how to assign object types. Also maybe it simply isn’t possible to operate on an InlineShape then copying/reassigning in PowerPoint.

Please let me know if anyone has any ideas, or if the description is too confusing.

Simplified Example:
Sub WordMacro ()

Dim wShape As InlineShape
Dim pptShape As Shape

Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

‘ Operate on screenshot

Selection.Copy
Set wShape = Selection.InlineShapes(1)

‘ Activate PowerPoint App

Set pptShape = wShape.ConvertToShape

‘ Operate on pptShape
End Sub

macropod
06-25-2014, 09:23 PM
Without knowing the specifics of what you're trying to do, only fairly general advice can be given. In Word you can choose to work with InlineShapes or Shapes. If you're exporting to PowerPoint, it really doesn't matter which you use unless there are properties attached to one format but not the other in Word. For example:

Sub Demo()
Dim wdShp As Word.Shape
Dim PptApp As PowerPoint.Application ' Object
Dim PptShw As PowerPoint.Presentation
Dim PptSld As PowerPoint.Slide
Dim PptShp As PowerPoint.Shape
Set wdShp = Selection.PasteSpecial(DataType:=wdPasteShape)
With wdShp
'Operate on screenshot
'
.Anchor.CopyAsPicture
End With
'Activate PowerPoint App
Set PptApp = CreateObject("PowerPoint.Application")
Set PptShw = PptApp.Presentations.Add
Set PptSld = PptShw.Slides(1)
Set PptShp = PptSld.Shapes.Paste
With PptShp
' Operate on pptShape
End With
End Sub
PS: When posting code, please use the code tags, indicated by the # button on the posting toolbar.

Duvdev
06-26-2014, 11:51 AM
Hello Paul,

Thank you for getting back, sorry the thread was a bit confusing. I didn't want to distract anyone from what I was trying to do by posting too much code, however it seems as though it would have been more beneficial to add more now that I have a better grasp on the issue.

Basically I had pasted a screenshot in Word and "operated" (re-sizing, cropping, etc) on the screenshot as an InlineShape. However I had written code in PowerPoint to do other similar manipulations to the same screenshot but "operating" on shapes (instead of InlineShapes). I was pasting the object into PPT but it seems as though the VBA focus was still set back to Word. I believe that my issue was that I was using code referring to "ActiveDocument" instead of "PowerPoint.Slide". Makes sense now after the fact why it lost focus on the Powerpoint, since the ActiveDocument refers to Word only.

I believe the reason why I used InlineShapes was to anchor the InlineShape to a range in Word, while in PowerPoint I have been moving the screenshots based on Shape properties. Really confusing at first just realizing the differences in the two.

I don't think I would have actually figured this one out for a while if I didn't have this example to re-evaluate what I doing. Thank you very much for the help!


Just in case if anyone else is looking for something similar (working on InlineShapes in Word and Shapes in PowerPoint using the same screenshot/object) hopefully something here will help out. I was able to get this to work by first pasting the screenshot to a specific slide, selecting the shape, then "operating" on the shape.

Sub Demo()
Dim wdShp As InlineShape
Dim PptApp As PowerPoint.Application ' Object
Dim PptShw As PowerPoint.Presentation
Dim PptSld As PowerPoint.Slide
Dim PptShp As PowerPoint.Shape
' Set wdShp = Selection.PasteSpecial(DataType:=wdPasteShape)
With wdShp
'Operate on screenshot
'
' .Anchor.CopyAsPicture

End With
'Activate PowerPoint App
Set PptApp = CreateObject("PowerPoint.Application")
Set PptShw = PptApp.Presentations.Add
Set PptSld = PptShw.Slides(1)
Set PptShp = PptSld.Shapes.Paste
PptShp.Select
With PptShp
' Operate on pptShape
End With
End Sub

' Code from Paul Edstein slightly edited to show concept

Also thank you for the info on code tags, knew it had to be somewhere but couldn't find it quickly enough. Hopefully this one posts correctly