Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Graphics Component For Microsoft ® Office Applications Programming In Visio ® – Part 1 Mr. David A. Edson, M.Arch. Technical Product Manager Developer.

Similar presentations


Presentation on theme: "A Graphics Component For Microsoft ® Office Applications Programming In Visio ® – Part 1 Mr. David A. Edson, M.Arch. Technical Product Manager Developer."— Presentation transcript:

1 A Graphics Component For Microsoft ® Office Applications Programming In Visio ® – Part 1 Mr. David A. Edson, M.Arch. Technical Product Manager Developer Tools Microsoft Corporation 4-301

2

3 A Graphics Component For Microsoft Office The key is DATA The key is DATA Visio is a means to visualize your data in graphical as well as textual form Visio is a means to visualize your data in graphical as well as textual form Businesses generate vast amounts of data daily Businesses generate vast amounts of data daily Various functional areas within businesses need to share that data Various functional areas within businesses need to share that data Not everyone comprehends data presented in its native format Not everyone comprehends data presented in its native format A picture is indeed worth a thousand words A picture is indeed worth a thousand words

4 Data Sharing Enabled Applications Access stores data as records comprised of fields Access stores data as records comprised of fields Excel stores data as arrays of inter-related cells Excel stores data as arrays of inter-related cells Word stores data as streams of text with embedded graphics Word stores data as streams of text with embedded graphics PowerPoint ® stores data as basic images of text and pictures PowerPoint ® stores data as basic images of text and pictures Outlook ® stores data as records of text and field related information Outlook ® stores data as records of text and field related information Visual Basic for Applications is the glue that binds these various data sources through automation Visual Basic for Applications is the glue that binds these various data sources through automation Visio communicates with all of these data sources through Visual Basic for Applications and other automation controllers Visio communicates with all of these data sources through Visual Basic for Applications and other automation controllers

5 Practical Examples Excel data into Visio diagrams Excel data into Visio diagrams  Organizational charting Visio data reported to Excel Visio data reported to Excel  Asset tracking and reporting Word data into Visio diagrams Word data into Visio diagrams  Literary structure Visio data reported to Word Visio data reported to Word  Business processes

6 But Before We Begin… Remember that the automation/object model is actually looking at Visio’s prime/core technology – the ShapeSheet ® interface Remember that the automation/object model is actually looking at Visio’s prime/core technology – the ShapeSheet ® interface Automation calls are actually feeding information into and pulling information from ShapeSheet cells – both for SmartShape ® symbols and the page itself Automation calls are actually feeding information into and pulling information from ShapeSheet cells – both for SmartShape ® symbols and the page itself

7 How Is The Data Shared? Robust object models are the key to data access and sharing Robust object models are the key to data access and sharing Object models are hierarchal structures Object models are hierarchal structures Each object has properties, methods and events Each object has properties, methods and events An object’s property may be an object further down the hierarchy An object’s property may be an object further down the hierarchy Through object models data is accessed and then read by another application Through object models data is accessed and then read by another application

8 Excel Application Object Visio Application Object Excel Workbooks Object Visio Documents Object Workbooks.Item Property > Excel Workbook Object Documents.Item Property > Visio Document Object Excel Workbook Object Visio Document Object Workbook.Worksh eet Property > Worksheets Object Document.Pages Property > Pages Object Excel Worksheets Object Visio Pages Object Worksheets.Item Property > Worksheet Object Pages.Item Property > Page Object Excel Worksheet Object Visio Page Object Worksheet.Cell Property > Cell Object Page.Shapes Property>Shapes Object Excel Cell Object Visio Shapes Object Shapes.Item Property>Shape Object Visio Shape Object Shape.Cells Property > Cell Object Cell.Result or Cell.Formula Cell.Value Excel - Visio Data Transfer

9 Traversing Visio’s Object Model Obtain a reference to the Application Object: Public Sub GetAppObject () Dim appVisio As Visio.Application Dim appVisio As Visio.Application Set appVisio = GetObject(“Visio.Application”) Set appVisio = GetObject(“Visio.Application”) End Sub

10 Traversing Visio’s Object Model Get a reference to the Documents Collection Object by calling upon the Documents Property of the Application Object: Public Sub GetDocsObject () Dim appVisio As Visio.Application Dim appVisio As Visio.Application Dim docsObj As Visio.Documents Dim docsObj As Visio.Documents Set appVisio = GetObject(“Visio.Application”) Set appVisio = GetObject(“Visio.Application”) Set docsObj = appVisio.Documents Set docsObj = appVisio.Documents End Sub

11 Traversing Visio’s Object Model Obtain a reference to the first document in the documents collection by calling upon the Item Property of the Documents Collection Object: Public Sub GetDocObject () Dim appVisio As Visio.Application Dim appVisio As Visio.Application Dim docsObj As Visio.Documents Dim docsObj As Visio.Documents Dim docObj As Visio.Document Dim docObj As Visio.Document Set appVisio = GetObject(“Visio.Application”) Set appVisio = GetObject(“Visio.Application”) Set docsObj = appVisio.Documents Set docsObj = appVisio.Documents Set docObj = docsObj.Item(1) Set docObj = docsObj.Item(1) End Sub

12 Traversing Visio’s Object Model Because Visio includes VBA, there is a very elegant shortcut to reference the currently active document. Keep in mind that it is not necessary to obtain a reference to the Application Object because owing to the fact that you are working within Visio’s VBA you already have an implicit reference to the Application Object: Public Sub GetDocObject () Dim docObj As Visio.Document Dim docObj As Visio.Document Set docObj = Visio.ActiveDocument Set docObj = Visio.ActiveDocument End Sub

13 Traversing Visio’s Object Model Obtain a reference to the collection of Pages in the document by calling upon the Pages Property of the Document Object: Public Sub GetPagsObject () Dim docObj As Visio.Document Dim docObj As Visio.Document Dim pagsObj As Visio.Pages Dim pagsObj As Visio.Pages Set docObj = Visio.ActiveDocument Set docObj = Visio.ActiveDocument Set pagsObj = docObj.Pages Set pagsObj = docObj.Pages End Sub

14 Traversing Visio’s Object Model Get a reference to the first Page in the Pages Collection by calling upon the Item Property of the Pages Collection Object: Public Sub GetPagObject () Dim docObj As Visio.Document Dim docObj As Visio.Document Dim pagsObj As Visio.Pages Dim pagsObj As Visio.Pages Dim pagObj As Visio.Page Dim pagObj As Visio.Page Set docObj = Visio.ActiveDocument Set docObj = Visio.ActiveDocument Set pagsObj = docObj.Pages Set pagsObj = docObj.Pages Set pagObj = pagsObj.Item(1) Set pagObj = pagsObj.Item(1) End Sub

15 Traversing Visio’s Object Model Again…there is a quick method of obtaining a reference to the currently active Page in a Visio document through VBA by referencing the ActivePage Object: Public Sub GetPagObject () Dim pagObj As Visio.Page Dim pagObj As Visio.Page Set pagObj = Visio.ActivePage Set pagObj = Visio.ActivePage End Sub

16 Traversing Visio’s Object Model Get a reference to the collection of Visio SmartShape symbols that reside on that page by calling the Shapes Property of the Page Object: Public Sub GetShpsObject () Dim pagObj As Visio.Page Dim pagObj As Visio.Page Dim shpsObj As Visio.Shapes Dim shpsObj As Visio.Shapes Set pagObj = Visio.ActivePage Set pagObj = Visio.ActivePage Set shpsObj = pagObj.Shapes Set shpsObj = pagObj.Shapes End Sub

17 Traversing Visio’s Object Model Get a reference to the first Visio SmartShape symbol on that Page by calling upon the Item Property of the Shapes Collection Object: Public Sub GetShpObject () Dim pagObj As Visio.Page Dim pagObj As Visio.Page Dim shpsObj As Visio.Shapes Dim shpsObj As Visio.Shapes Dim shpObj As Visio.Shape Dim shpObj As Visio.Shape Set pagObj = Visio.ActivePage Set pagObj = Visio.ActivePage Set shpsObj = pagObj.Shapes Set shpsObj = pagObj.Shapes Set shpObj = shpsObj.Item(1) Set shpObj = shpsObj.Item(1) End Sub

18 Traversing Visio’s Object Model An alternate to obtaining a SmartShape symbol by index is calling for it by its name: Public Sub GetShpObject () Dim pagObj As Visio.Page Dim pagObj As Visio.Page Dim shpsObj As Visio.Shapes Dim shpsObj As Visio.Shapes Dim shpObj As Visio.Shape Dim shpObj As Visio.Shape Set pagObj = Visio.ActivePage Set pagObj = Visio.ActivePage Set shpsObj = pagObj.Shapes Set shpsObj = pagObj.Shapes Set shpObj = shpsObj.Item(“Connector.1”) Set shpObj = shpsObj.Item(“Connector.1”) End Sub This presumes that a SmartShape symbol exists on the active Page which has the name of “Connector.1”

19 Traversing Visio’s Object Model Yet another alternative is to obtain the reference to the desired Visio SmartShape Symbol by locating the currently selected SmartShape Symbol. To do this we utilize the Selection Property of the Active Window Object and select the first Item in the Selection: Public Sub GetShpObject () Dim windObj As Visio.Window Dim windObj As Visio.Window Dim shpObj As Visio.Shape Dim shpObj As Visio.Shape SetwindObj = Visio.ActiveWindow SetwindObj = Visio.ActiveWindow Set shpObj = windObj.Selection.Item(1) Set shpObj = windObj.Selection.Item(1) End Sub

20 Traversing Visio’s Object Model Now that we have a reference to the SmartShape symbol in question we can obtain a reference to the Width Cell. We do this by calling for the Cells property of the Shape Object: Public Sub GetCelObject () Dim windObj As Visio.Window Dim windObj As Visio.Window Dim shpObj As Visio.Shape Dim shpObj As Visio.Shape Dim celObj As Visio.Cell Dim celObj As Visio.Cell SetwindObj = Visio.ActiveWindow SetwindObj = Visio.ActiveWindow Set shpObj = windObj.Selection.Item(1) Set shpObj = windObj.Selection.Item(1) Set celObj = shpObj.Cells(“Width”) Set celObj = shpObj.Cells(“Width”) End Sub Note that the Cells Property contains a mandatory argument which is the name of the cell we wish to reference

21 Traversing Visio’s Object Model Finally, with a Cell Object referenced, we can extract the value in the cell by calling for the Result Property of the Cell Object, specifying the units we wish to see the value returned in. The value will be returned as a double: Public Sub GetCelValue () Dim windObj As Visio.Window Dim windObj As Visio.Window Dim shpObj As Visio.Shape Dim shpObj As Visio.Shape Dim celObj As Visio.Cell Dim celObj As Visio.Cell Dim celVal As Double Dim celVal As Double SetwindObj = Visio.ActiveWindow SetwindObj = Visio.ActiveWindow Set shpObj = windObj.Selection.Item(1) Set shpObj = windObj.Selection.Item(1) Set celObj = shpObj.Cells(“Width”) Set celObj = shpObj.Cells(“Width”) CelVal = celObj.Result(“in.”) CelVal = celObj.Result(“in.”) End Sub

22 More Tips, Tricks And Toys… Using Visio’s Database Wizard Using Visio’s Database Wizard Using Visio’s OrgChart Wizard Using Visio’s OrgChart Wizard

23 Thank You! Remember your evaluations (what can make this better?) Contact: Mr. David A. Edson, M.Arch. Technical Product Manager Developer Tools Marketing Microsoft Corporation davided@microsoft.com Contact: Mr. David A. Edson, M.Arch. Technical Product Manager Developer Tools Marketing Microsoft Corporation davided@microsoft.com

24


Download ppt "A Graphics Component For Microsoft ® Office Applications Programming In Visio ® – Part 1 Mr. David A. Edson, M.Arch. Technical Product Manager Developer."

Similar presentations


Ads by Google