==[[Visio ER図の情報を取得する]]==
[[Visio]] | [[VBA]] |
===モジュール===
VisioのER図をCSV出力するマクロ[[Visio]]のER図をCSV出力するマクロ{{ref MakeVisioEntityListMake[[Visio]]EntityList.zip}}
<blockquote>メタ情報が取得しかたがわからない(そもそもできる?)。。。</blockquote>
Private Const IS_LOGGING As Boolean = True
'除外するVisioシート名除外する[[Visio]]シート名(一部一致をカンマ区切り) Private Const EXCEPT_SHEET_KEYWORD EXCEPT_SHEET_KEYWO[[R]]D As String = "背景"
'エンティティを識別するためのマスターシェイプ名
Private Const MASTER_SHAPE_ENTITY_NAME_U MASTE[[R]]_SHAPE_ENTITY_NAME_U As String = "Entity"
'
Set entityDict = CreateObject("Scripting.Dictionary")
'Visioドキュメントのページ単位で処理[[Visio]]ドキュメントのページ単位で処理
Set docPages = Application.ActiveDocument.Pages
docPageCnt = docPages.Count
For i = 1 To docPageCnt
'Entity辞書のクリア
Call entityDict.RemoveAll[[R]]emoveAll
Set docPage = docPages.Item(i)
' シートごとの処理
'
Private Sub ParsePage(ByRef By[[R]]ef docPage As Page, ByRef By[[R]]ef entityDict As Object)
Dim docShapes As Shapes
Select Case True
Case InStr(1, docShapeNameU, MASTER_SHAPE_ENTITY_NAME_UMASTE[[R]]_SHAPE_ENTITY_NAME_U) = 1
' テーブル、列、データ型
Call ProcEntity(docShapes(i), entityDict)
' エンティティ処理
'
Private Sub ProcEntity(ByRef By[[R]]ef entityShape As Shape, ByRef By[[R]]ef entityDict As Object)
Dim partsShapes As Shapes
Dim partsShape As Shape
Dim ent As Entity
Dim col As Column
Dim rareRowrare[[R]]ow() As String Dim splitedRowsplited[[R]]ow() As String
Set partsShapes = entityShape.Shapes
Case 2
'2:列情報
rareRow rare[[R]]ow = Split(partsShape.Text, vbLf) For j = LBound(rareRowrare[[R]]ow) To UBound(rareRowrare[[R]]ow) splitedRow splited[[R]]ow = SplitRowSplit[[R]]ow(rareRowrare[[R]]ow(j))
Set col = New Column
col.Name = splitedRowsplited[[R]]ow(0) col.DataType = splitedRowsplited[[R]]ow(1)
If Trim(col.Name) <> "" Then
' 列名とデータ型を分ける
'
Private Function SplitRowSplit[[R]]ow(ByRef By[[R]]ef row As String) As String() Const COL_SEP_CHAR COL_SEP_CHA[[R]] As String = vbTab
Dim sepPos As Integer
Dim i As Integer
If Trim(row) <> "" Then
tmp = Split(row, COL_SEP_CHARCOL_SEP_CHA[[R]])
If UBound(tmp) > 0 Then
End If
End If
SplitRow Split[[R]]ow = ret
End Function
Dim i As Integer
keywords = Split(EXCEPT_SHEET_KEYWORDEXCEPT_SHEET_KEYWO[[R]]D, ",")
For i = LBound(keywords) To UBound(keywords)
Columns = mColumns
End Property
Public Property Let Columns(ByRef By[[R]]ef newColumns() As Column)
Set mColumns = newColumns
End Property
Public Sub AddColumn(ByRef By[[R]]ef col As Column)
ReDim [[R]]eDim Preserve mColumns(mColumnCnt)
Set mColumns(mColumnCnt) = col