Opening a second visio file in early binding with Excel, to copy shapes between visio files

I use Excel vba procedures to open and manipulate visio drawings:
To selecting a file in a dialogue box:

visFilePath = Application.GetSaveAsFilename(options_EndUser_OpenFile_DefaultPath, fileFilterString) 'default defined by Const
    If visFilePath <> "False" Then
        exists = FileFolderExists(visFilePath)
        dialgBxVisFileChosen = True
    Else
        dialgBxVisFileChosen = False
        Exit Sub
    End If

and then early binding:

If Not IsFileOpen(visFilePath) Then
       Set visioApp = New Visio.Application 'early binding
       Set visQDoc = visioApp.Documents.Open(visFilePath)
       Set pgs = visQDoc.Pages
end if

Now I want to open a second visio file so I can copy visio shapes from one file to the other.

I'm trying to work out a simple scheme, and worry that I will run into gotchas..
I propose to make two versions of all the variables above, distinguishing a don_vis file (copy domor) and rec_vis file (copy recipient): extending for example:

don_visFilePath & rec_visFilePath
don_visioApp    & rec_visioApp   etc etc

The inter file copying code would be focused on don_shapes and rec_shapes as members of  don_pages and rec_pages collections.

I can send event signals between excel and visio, in either direction, and have copied shapes within single visio files.

What worries me about my simple approach is, inexperience!  Where is this simple approach likely to cause me problems?


Thanks, Kelvin4
Kelvin4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
What you're describing is pretty straightforward as far as I can tell. The only thing that occurs to me is to be careful that you don't refer to ActiveDocument or any other "active" object. You probably don't do this anyway because your code is running in Excel not Visio, but I thought I'd mention it.

Other than that, Just be sure you keep your donor and receiver variables straight (especially each time you copy and paste a chunk of code to reuse it), and you should be fine.
0
Visio_GuyCommented:
I think it helps to break things up into as many small functions/subs as possible. Also, I personally use "from" and "to" in my variable names for stuff like this. Maybe:

'// Here's the main routine. It takes a 'from' page and a 'to' page as arguments.
Public Sub CopyShapes( ByRef visPgFrom As Visio.Page, _
                       ByRef visPgTo As Visio.Page )

  Dim shp As Visio.Shape
  For Each shp in visPgFrom.Shapes
    Call m_copyShape( shp, visPgTo )
  Next shp

  '// Cleanup:
  Set shp = Nothing

End Sub

Private Sub m_copyShape( ByRef visShpFrom As Visio.Shape, _
                         ByRef visPgTo As Visio.Page  )

  '// Location of 'from' shape on 'from' page:
  Dim px As Double, py As Double
  px = visShpFrom.CellsU("PinX").ResultIU
  py = visShpFrom.CellsU("PinY").ResultIU

  '// Drop 'from' shape on 'to' page:
  Dim shp As Visio.Shape
  Set shp = visPgTo.Drop( visShpFrom, px, py )

  '// Set the date and time this happened in the shape's
  '// as an example of doing something interesting in the
  '// 'to' page:
  shp.Text = Format(Now(), "yyyy.mm.dd-hh:mm:ss")

  '// If this was a function instead of a Sub, we could return
  '// the shape object:
  '// Set m_copyShape = shp

  '// Cleanup:
  Set shp = Nothing

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelvin4Author Commented:
Thanks!
Kelvin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Visio

From novice to tech pro — start learning today.