Automatic Master selection with data from external Excel file

Started by Nico G, June 24, 2013, 04:10:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nico G

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

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

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

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

Ok, thanks a lot al, I'm going to find a way to code it :)

Nico G

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.



'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