Hi,
i want to add entity in empty crow's foot diagram.
So open new page and add entity "tblDisks" with 3 fields:
1. Primary Key Attribute - "DiskID"
2. FieldName - DiskName
3. FieldName - DiskSize
How can i achieve this?
Best,
Jacek
Hi, Jacek !
Start macro-recorder, do these steps with user interface and analyze code.
hi,
thank you.
Maybe it is good way to start.
Maybe any examples?
Best,
Jacek
Hello Jacek,
there seems to be a misunderstanding.
In Visio there is a feature called "macro recorder". It is only available if you set your Visio application in "developer" mode.
Once started, this feature makes Visio write in VBA every thing you do manually in the UI.
The so recorded code (the macro) can then be edited to make suitable for generic use.
Witaj Jacek,
wydaje się, że istnieje nieporozumienie.
W Visio istnieje funkcja zwana "makro rejestratorem". Jest ona dostępna tylko wtedy, gdy aplikacja Visio jest ustawiona w trybie "deweloperskim".
Po uruchomieniu ta funkcja sprawia, że Visio pisze w VBA każdą rzecz, którą robisz ręcznie w interfejsie użytkownika.
Zarejestrowany w ten sposób kod (makro) można następnie edytować w celu dostosowania go do użytku ogólnego.
hi Yacine,
thank you. It is the best way to create macros in Visio? Recording them?
In Excel recorded macro have very bad performence and using not very fast methods and properties...
Best,
Jacek
Hi, Jacek !
Of course recorded macros have not best performance, but this way is better for persons who not familiar with VBA in MS Visio.
@Jacek,
no, the macro recorder is not meant to make a final perfect macro. But it shows you the VBA commands you are looking for.
In your case the question is "how can I draw a shape?" or "how can I a drop a master from a stencil on the drawing?". The recorder will show you that "drop" is the right command.
Now you have to manually write your VBA code, where you define the target (activepage), the stencil (either hard coded or entered by means of a dialog), same for the master, an so on.
First recorded macro - using the mectric basic shapes stencils could look as follows:
Sub Macro1()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Application.Windows.ItemEx("Drawing1 [Compatibility Mode]").Activate
Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle"), 4.527559, 8.464567
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
There will be very little left when you strip all the unnecessary parts:
Sub Macro1()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Application.Windows.ItemEx("Drawing1 [Compatibility Mode]").Activate
Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle"), 4.527559, 8.464567
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
You get: "Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle"), 4.527559, 8.464567"
Now you strip the line into single parts Application.ActiveWindow.Page.Drop Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle"), 4.527559, 8.464567. Drop is the command identified - you google it and find out that you need a target (red), a source (blue) and a position (green) where to drop the shape.
The elements (target, source, ...) are unfortunately always formulated in a very specific way. You need to learn to understand and reformulate them. That's something you need to find out and get accustomed to. -
Application.ActiveWindow.Page translates to "activepage".
-
Application.Documents.Item("BASIC_M.VSSX").Masters.ItemU("Rectangle") could be translated for sake of generalisation into:
dim myStencilSting as string
dim myMasterString as string
dim shp as shape
Then you would re-write the macro to:
myMasterString = "Rectangle" 'or dynamic input
myStencilString = "Basic_M.VSSX" 'or dynamic input
x=0
y=0
set shp = ActivePage.drop (ActiveDocument.Item(myStencilString, myMasterString, x,y)