Visio Moving Shapes - What is wrong in that code?

D

Daniel H.

' I want to Move a grouped shape for the different distance to its
' original Object
' I can not acces the Cells
' app,res,result ... Object
' pinx,piny ... Long

Set app = Master.GetWindowObject
app.Selection.SelectAll
Set res = app.Selection.Group
pinx = res.Cells("PinX")
piny = res.Cells("PinY")
app.Selection.Copy visCopyPasteNoTranslate
app.Selection.Ungroup

Set objCopiedPage = objPages.Add()
objCopiedPage.Paste visCopyPasteNoTranslate
app.Selection.SelectAll
result.Cells("PinX") = result.Cells("PinX") + (pinx - result.Cells("PinX"))
result.Cells("PinY") = result.Cells("PinY") + (piny - result.Cells("PinY"))
app.Selection.Ungroup
 
M

Mark Nelson [MS]

Could you clarify what you are trying to do? It looks like you are trying
to copy shapes from one page to another, keeping them in the same place on
each page.
 
A

Al Edlund

This is what I use as part of a 'library copy' set of routines. Note that
you should move the pasted group(and use the groups pinx,piny) to the new
location before ungrouping it so they are moved as a group in the original
format.

Al


Private Function funcCopyPage(tgtPage As Visio.Page, srcPage As Visio.Page)
As Boolean

' tgtwin and srcwin are defined globally and manipulated my multiple
' processes and functions, so they are initialized elsewhere in a previous
routine
' Public tgtWin As Visio.Window
' Public srcWin As Visio.Window
' there is a separate function called before this that copies the page
formats
' between the source and target to insure that they match as well


Dim strPageName As String
Dim curWin As Visio.Window
Dim strCurStep As String

On Error GoTo CopyPage_Err

' go to the source window
strCurStep = "activate source win"

Visio.Application.ScreenUpdating = False

srcWin.Activate
ActivePage.Name = srcPage.Name
' brute force method of copy
strCurStep = "Copy source"
ActiveWindow.SelectAll
ActiveWindow.Group
ActiveWindow.Copy

' now go and paste it
strCurStep = "activate target win"
tgtWin.Activate
strCurStep = "set target active page"
ActivePage.Name = tgtPage.Name
ActivePage.Paste , visCopyPasteNoTranslate

Visio.Application.ScreenUpdating = True

' since what has been pasted should still be selected
' assign to an object and then move it or since everything
' was selected on the original page just center it

ActivePage.CenterDrawing

funcCopyPage = True

CopyPage_Exit:
DoEvents
Exit Function

CopyPage_Err:

Debug.Print "Error CopyPage Cur Step = "; strCurStep
Debug.Print "Error CopyPage " & Err.Number & ": " & Err.Description
funcCopyPage = False
Resume CopyPage_Exit

End Function
 
M

Mark Nelson [MS]

If you are using visCopyPasteNoTranslate, then you should not need to store
any position information or fix up any position information.

--
Mark Nelson
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.


Daniel H. said:
Yes but it does not work and so i want somebody to tell me why

"Mark Nelson [MS]" <[email protected]> wrote in message
Could you clarify what you are trying to do? It looks like you are trying
to copy shapes from one page to another, keeping them in the same place on
each page.

--
Mark Nelson
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top