Pasting shapes into pre-defined areas

Started by John Distai, May 20, 2009, 07:11:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John Distai

Hi,

Does anyone know if there is a way to paste shapes to a specific area of the page using code?  I can see how to have shapes drawn where I want, but I don't see a way to paste them where I want.  Currently, pasting the shapes through code makes the shapes appear in the center of the page.  I would like to paste them off the page.  Any ideas on how to do this?

Thanks!

JD

Paul Herber

Once the shapes have been pasted they are still the current selection, so use the ActiveWindow.Selection.ContainingShape.Cells[] to set the selection PinX and PinY etc.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Visio Guy

Perhaps use the Drop method instead of paste?

Here's two methods. The simpler one works, but gives an odd error (that you could trap and ignore, but that kind of feels yucky)


Sub DropSelInCorner()

  '// Select some shapes on the page, first:
  Dim sel As Visio.Selection
  Set sel = Visio.ActiveWindow.Selection
 
  If sel.Count = 0 Then Exit Sub
 
  '// Use drop to drop the group somewhere.
  '// This works, but it gives a funny error:
  Dim selNew As Visio.Selection
  Set selNew = Visio.ActivePage.Drop(sel, 8.5, 11)
   
End Sub


Sub DropSelInCornerButGroupFirst()

  '// Select some shapes on the page, first:
  Dim sel As Visio.Selection
  Set sel = Visio.ActiveWindow.Selection
 
  If sel.Count = 0 Then Exit Sub
 
  '// Group the selection:
  Dim shpGrp As Visio.Shape
  Set shpGrp = sel.Group
 
  '// Drop a copy somewhere on the page:
  Dim shpGrpNew As Visio.Shape
  Set shpGrpNew = Visio.ActivePage.Drop(shpGrp, 8.5, 11)
   
  '// Ungroup both groups:
  Call shpGrp.Ungroup
  Call shpGrpNew.Ungroup
 
End Sub
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010