Author Topic: Automatic Master selection with data from external Excel file  (Read 5530 times)

0 Members and 1 Guest are viewing this topic.

Nico G

  • Newbie
  • *
  • Posts: 4
Hello folks,

I'm using Visio Premium 2010.

I want to build maps from JPG pictures with items on it, representing servers, PCs, printers or whatever. In order to do that I import the JPG into Visio and connect it to an external database (Excel file) with all the equipment description, value, unique ID and so on. A column in the Excel file represent the type of equipment (again: PC, Printer...). Everything works perfectly except that I when I drag and drop a value from my external database the Master (the shape) is not selected automatically.

Is there a way to automatically select the Master depending a value in the Excel File?

I tried to navigate through the forum to find answer to my question, but couldn't find exactly what I need. But since I'm completely new to Visio, maybe I don't use the correct wording :)


aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: Automatic Master selection with data from external Excel file
« Reply #1 on: June 24, 2013, 04:51:06 PM »
I'm not quite sure of the flow you're attempting to accomplish.
" Everything works perfectly except that I when I drag and drop a value from my external database the Master (the shape) is not selected automatically."
al


Nico G

  • Newbie
  • *
  • Posts: 4
Re: Automatic Master selection with data from external Excel file
« Reply #2 on: June 25, 2013, 06:33:56 AM »
When I drag a value from the "External Data" panel (see picture attached) and drop it on a page the shape selected is the last Master Shape I used. I would like to get a shape according to a value in the external database.

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: Automatic Master selection with data from external Excel file
« Reply #3 on: June 25, 2013, 08:15:52 AM »
Unfortunately that form of shape selection (dragging a record) does bring the last master selected to the page. You'll probably have to write a little code to get what you want
pseudo code

wait for shape dropped event
if new shape is linked to a datarecordset
compare shape master with desired shape
if shapes are different
delete new shape and add the shape from the datarecordset

al

Nico G

  • Newbie
  • *
  • Posts: 4
Re: Automatic Master selection with data from external Excel file
« Reply #4 on: June 25, 2013, 09:02:49 AM »
Ok, thanks a lot al, I'm going to find a way to code it :)

Nico G

  • Newbie
  • *
  • Posts: 4
Re: Automatic Master selection with data from external Excel file
« Reply #5 on: July 03, 2013, 03:59:53 AM »
Hello, I found out that replacing a shape is quite easy with Visio 2013. Therefore I made this crappy code. Sry I have never learnt how to program VBA.

Code

'AUTOMATIC SHAPE SELECTION
'03/07/2013
'Nicolas Galozio
'
Private Sub Document_ShapeAdded(ByVal Shape As IVShape)
   
    On Error GoTo GestionErreur
   
    'VARIABLES INIT
    Dim MasterIconeAjout As Master
    Dim MasterNomExcel As String
    'If your Visio diagrams have been used with Data | Link Data to Shapes,
    'then you need to know that this feature will attempt to link the data by matching the text in the Shape Data row's Label cell with the column header,
    'or the field name of the external data first and it is case-sensitive.
    'If the target shape does not already have a Shape Data row, then Visio will automatically create a row named after the Label text, but with a _VisDM_ prefix,
    'and any spaces or special characters removed.
    'http://msdn.microsoft.com/en-us/library/office/gg144579%28v=office.14%29.aspx
    MasterNomExcel = "_VisDM_Icon"
    Dim MasterNomSouhaite As String
    Set MasterIconeAjout = Shape.Master
    'Stencil name to use
    Set StencilAUtiliser = Application.Documents("MPS.VSSX")
       
    'MASTER SHAPE NAME DROP ON THE PAGE
    MasterIconeAjoutNom = Replace(MasterIconeAjout.Name, "." & MasterIconeAjout.ID, "")
    'MsgBox MasterIconeAjoutNom
   
    'SHAPE NAME WANTED IN THE EXCEL COLUMN
    If Shape.CellExistsU("Prop." & MasterNomExcel, 0) Then
        MasterNomSouhaite = Shape.CellsU("Prop." & MasterNomExcel).ResultStr(visNone)
    Else
        MsgBox ("Elle est où la colonne " & MasterNomExcel & "?")
        Exit Sub
    End If
    'MsgBox MasterNomSouhaite
   
    'SHAPE REPLACEMENT IF NAME IS DIFFERENT
    If MasterIconeAjoutNom <> MasterNomSouhaite Then
        Shape.ReplaceShape StencilAUtiliser.Masters(MasterNomSouhaite)
    End If
   
'I THINK WE HAVE AN ISSUE
GestionErreur:
    MsgBox "J'ai pas trouvé le Master pour ça. En gros y'a une erreur quoi."
    Exit Sub
   
End Sub