Problems with images pasted via the clipboard 
Author Message
 Problems with images pasted via the clipboard
Hello,

I'm writing a macro, that should export text and images from PPT
(XP)to Word (XP).
Exporting the pictures I causes a problem in Word, working on the
images.

Here some snippets from the code:

----
Sub exportImages()
    Set wrdapp = CreateObject("Word.Application")
    wrdapp.Visible = True
    wrdapp.Documents.Add DocumentType:=wdNewBlankDocument

    Dim s As Slide

    For Each s In ActivePresentation.Slides
        Dim i As Integer
        s.Select
        MsgBox ActiveWindow.Selection.SlideRange.Shapes.Count
        For i = 2 To ActiveWindow.Selection.SlideRange.Shapes.Count
            With ActiveWindow.Selection.SlideRange.Shapes(i)
                If .Type = msoPicture Then
                    .Copy
                    wrdapp.Selection.Paste
                    wrdapp.Selection.MoveDown
                    wrdapp.Selection.TypeParagraph
                End If
            End With
        Next i
    Next s
    wrdapp.Quit
    Set wrdapp = Nothing
End Sub
----
This works fine and e.g. if there are three "real" images
(shape.type=msoPicture)
in the presentation, all three pictures are afterward in Word.
Trying to convert them to inlineshapes,
----
Sub convertShapes()
'
' IterateShapes Makro
'
    Dim objshape As Shape
    For Each objshape In ActiveDocument.Shapes
        objshape.ConvertToInlineShape
    Next objshape
End Sub
----
every shape-object becomes two!! inlineshape-objects, which are next
to each other in the line.
In page-layout view, the left looks like the picture before, the right
is a empty border, which
you only see in Word when clicking on it!

I have tries something and googled for help, but I don't know what to
do now.

Please help,
if you need some more code snippets or a example file, i will post.

thx
Martin

PS: I hope the group is zhe right to post to.



Sat, 05 Mar 2005 01:25:00 GMT  
 Problems with images pasted via the clipboard
Hi Martin,

I haven't actually tested your code but know that looping through some collections of objects and deleting one inside the loop (that's what actually is happening in your case) don't always work as you should expect (read: misbehave ;-)
What happens if you add a counter and loop like:

     Dim i as Integer

     For i = ActiveDocument.Shapes.Count to 1 Step -1
         ActiveDocument.Shapes(i).ConvertToInlineShape
     Next i

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/


Quote:
> Hello,

> I'm writing a macro, that should export text and images from PPT
> (XP)to Word (XP).
> Exporting the pictures I causes a problem in Word, working on the
> images.

> Here some snippets from the code:

> ----
> Sub exportImages()
>     Set wrdapp = CreateObject("Word.Application")
>     wrdapp.Visible = True
>     wrdapp.Documents.Add DocumentType:=wdNewBlankDocument

>     Dim s As Slide

>     For Each s In ActivePresentation.Slides
>         Dim i As Integer
>         s.Select
>         MsgBox ActiveWindow.Selection.SlideRange.Shapes.Count
>         For i = 2 To ActiveWindow.Selection.SlideRange.Shapes.Count
>             With ActiveWindow.Selection.SlideRange.Shapes(i)
>                 If .Type = msoPicture Then
>                     .Copy
>                     wrdapp.Selection.Paste
>                     wrdapp.Selection.MoveDown
>                     wrdapp.Selection.TypeParagraph
>                 End If
>             End With
>         Next i
>     Next s
>     wrdapp.Quit
>     Set wrdapp = Nothing
> End Sub
> ----
> This works fine and e.g. if there are three "real" images
> (shape.type=msoPicture)
> in the presentation, all three pictures are afterward in Word.
> Trying to convert them to inlineshapes,
> ----
> Sub convertShapes()
> '
> ' IterateShapes Makro
> '
>     Dim objshape As Shape
>     For Each objshape In ActiveDocument.Shapes
>         objshape.ConvertToInlineShape
>     Next objshape
> End Sub
> ----
> every shape-object becomes two!! inlineshape-objects, which are next
> to each other in the line.
> In page-layout view, the left looks like the picture before, the right
> is a empty border, which
> you only see in Word when clicking on it!

> I have tries something and googled for help, but I don't know what to
> do now.

> Please help,
> if you need some more code snippets or a example file, i will post.

> thx
> Martin

> PS: I hope the group is zhe right to post to.



Sun, 06 Mar 2005 05:10:34 GMT  
 Problems with images pasted via the clipboard
Hi,

thank for te tip, but the behaviour is the same.
I recognized that, when I resize the picture in Word and move it, then
there is an empty border at the origin position.
Before the action Word says, that there is one shape-object in the
document, afterwards it says, there are one inlineshape-object (the
empty border) and one shape-object (the picture).
In the context-menu to the border, there is the entry "format
autoform".
Could it be that at pasting a picture there were inserted a picture
and a "autoform-border" ore something else?
And how can i automatically find autoforms-object in word-documents.

thx for help
Martin

Quote:

> Hi Martin,

> I haven't actually tested your code but know that looping through some
> collections of objects and deleting one inside the loop (that's what
> actually is happening in your case) don't always work as you should
> expect (read: misbehave ;-)
> > I'm writing a macro, that should export text and images from PPT
> > (XP)to Word (XP).
> > Exporting the pictures I causes a problem in Word, working on the
> > images.

> > Here some snippets from the code:

> > ----
> > Sub exportImages()
> >     Set wrdapp = CreateObject("Word.Application")
> >     wrdapp.Visible = True
> >     wrdapp.Documents.Add DocumentType:=wdNewBlankDocument

> >     Dim s As Slide

> >     For Each s In ActivePresentation.Slides
> >         Dim i As Integer
> >         s.Select
> >         MsgBox ActiveWindow.Selection.SlideRange.Shapes.Count
> >         For i = 2 To ActiveWindow.Selection.SlideRange.Shapes.Count
> >             With ActiveWindow.Selection.SlideRange.Shapes(i)
> >                 If .Type = msoPicture Then
> >                     .Copy
> >                     wrdapp.Selection.Paste
> >                     wrdapp.Selection.MoveDown
> >                     wrdapp.Selection.TypeParagraph
> >                 End If
> >             End With
> >         Next i
> >     Next s
> >     wrdapp.Quit
> >     Set wrdapp = Nothing
> > End Sub
> > ----
> > This works fine and e.g. if there are three "real" images
> > (shape.type=msoPicture)
> > in the presentation, all three pictures are afterward in Word.
> > Trying to convert them to inlineshapes,
> > ----
> > Sub convertShapes()
> > '
> > ' IterateShapes Makro
> > '
> >     Dim objshape As Shape
> >     For Each objshape In ActiveDocument.Shapes
> >         objshape.ConvertToInlineShape
> >     Next objshape
> > End Sub
> > ----
> > every shape-object becomes two!! inlineshape-objects, which are next
> > to each other in the line.
> > In page-layout view, the left looks like the picture before, the right
> > is a empty border, which
> > you only see in Word when clicking on it!

> > I have tries something and googled for help, but I don't know what to
> > do now.

> > Please help,
> > if you need some more code snippets or a example file, i will post.

> > thx
> > Martin

> > PS: I hope the group is zhe right to post to.



Sun, 06 Mar 2005 18:39:01 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. paste from clipboard to Image Box

2. paste from clipboard to image box in VB6

3. Paste an image from Clipboard to RTFTextBox

4. Paste image from clipboard to file

5. Pasting Clipboard image to a RichTextBox Control

6. Excel 97 - problem with activesheet.paste from clipboard in macro

7. Problem pasting from clipboard

8. PaintPicture / Paste to Clipboard Problem

9. Excel Image to Clipboard to Image Control

10. COPY AND PASTE FROM GLOBAL CLIPBOARD IN VBA

11. Paste records from the clipboard

12. Pasting data from clipboard

 

 
Powered by phpBB® Forum Software