Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 19 Aug 2008 09:57:01 -0700,    group: microsoft.public.word.vba.general        back       


Help with grouping shapes in 2007   
Need help with vba code that worked in Word-2003 but fails in 2007.
We have reports that add annotated diagrams (using .wmf images and autoshape 
marks placed according to data in the report)
To get this done (in 2003), my code opens a blank document, adds the diagram 
and the shapes, then groups these and copies them back to a bookmark in the 
report.  This code fails however in word 2007, (seems the graphics 
capabilities are reduced?)

The code block below illustrates the problem, or you can see it by hand if 
you manually add a small wmf file to a document then add an autoshape and try 
to group them.  
In 2003 you can simply select both (by holding the shift key) but not in 
2007 - it will only select one or the other.   
An added note - In 2007 you can select a (manually placed) wmf and in the 
right mouse menu select 'edit picture' at which point there is the capability 
to manually group.   However, I have been unable to achieve this from code 
(and the option is actually grayed out when you right mouse click an image 
that was placed with the code below!)

'---------
sub OKIn2003Not2007
    Set ad = ActiveDocument
    ad.Shapes.AddPicture "c:/diagram.wmf"
    ad.Shapes.AddShape Type:=msoShape5pointStar, _
                                    Left:=82.3, Top:=98, _
                                    Width:=18, Height:=18

    ad.Shapes.SelectAll                           ' This fails in 2007 -
    ad.Range.ShapeRange.Group.Select    ' This is what i am trying to get done
    Selection.Cut                  
    ' Then I do inline paste of shape group to a bookmark
End sub
'-------

Thanks in advance for any answers.
Scott Wiley
date: Tue, 19 Aug 2008 09:57:01 -0700   author:   scottw

RE: Help with grouping shapes in 2007   
Have solved this problem so I will share the solution.
Thanks to anyone that may have spent time trying to help.

In words:
First add a drawing canvas (larger than the diagram) then add the pictures & 
shapes to the canvas.  Then select cut & paste the canvasitems –
The following block is now working in 2007
In code:
'-------
    Dim pic As Shape
    Dim shpNext As Shape
    Dim cvs As Shape
    Set cvs = ad.Shapes.AddCanvas(0, 0, 333, 333)
    Set pic = cvs.CanvasItems.AddPicture("c:/diagram.wmf", False, True, 0, 0)
    Set shpNext = cvs.CanvasItems.AddShape(msoShape5pointStar, _
                                     Left:=82.3, Top:=98, _
                                     Width:=18, Height:=18
    shpNext.Fill.ForeColor = wdColorRed                                      
      
    cvs.CanvasItems.SelectAll
    Selection.Cut
    cvs.delete  'not needed 
'----------


"scottw" wrote:

> Need help with vba code that worked in Word-2003 but fails in 2007.
> We have reports that add annotated diagrams (using .wmf images and autoshape 
> marks placed according to data in the report)
> To get this done (in 2003), my code opens a blank document, adds the diagram 
> and the shapes, then groups these and copies them back to a bookmark in the 
> report.  This code fails however in word 2007, (seems the graphics 
> capabilities are reduced?)
> 
> The code block below illustrates the problem, or you can see it by hand if 
> you manually add a small wmf file to a document then add an autoshape and try 
> to group them.  
> In 2003 you can simply select both (by holding the shift key) but not in 
> 2007 - it will only select one or the other.   
> An added note - In 2007 you can select a (manually placed) wmf and in the 
> right mouse menu select 'edit picture' at which point there is the capability 
> to manually group.   However, I have been unable to achieve this from code 
> (and the option is actually grayed out when you right mouse click an image 
> that was placed with the code below!)
> 
> '---------
> sub OKIn2003Not2007
>     Set ad = ActiveDocument
>     ad.Shapes.AddPicture "c:/diagram.wmf"
>     ad.Shapes.AddShape Type:=msoShape5pointStar, _
>                                     Left:=82.3, Top:=98, _
>                                     Width:=18, Height:=18
> 
>     ad.Shapes.SelectAll                           ' This fails in 2007 -
>     ad.Range.ShapeRange.Group.Select    ' This is what i am trying to get done
>     Selection.Cut                  
>     ' Then I do inline paste of shape group to a bookmark
> End sub
> '-------
> 
> Thanks in advance for any answers.
> Scott Wiley
date: Wed, 20 Aug 2008 18:08:14 -0700   author:   scottw

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us