• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Getting Data from Excel

To access the information in an Excel cell, use the Value property of the cell object and store the result in a variable or pass it directly to Visio as in Listing 21.2.

Listing 21.2. Getting an Excel Cell's Value

Public Sub GrabFromExcel()
    Dim shpObj As Visio.Shape
    Dim celObj As Visio.Cell
    Dim xlObjApp As Excel.Application
    Dim xlObjBook As Excel.Workbook
    Dim xlObjSheet As Excel.Worksheet
    Dim xlObjCell As Excel.Range
    Set shpObj = Visio.ActiveWindow.Selection.Item(1)
    Set celObj = shpObj.Cells("Prop.Duration")
    Set xlObjApp = GetObject(, "Excel.Application")
    Set xlObjBook = xlObjApp.Workbooks.Item("TestCase.XLS")
    Set xlObjSheet = xlObjBook.Worksheets.Item("Sheet1")
    Set xlObjCell = xlObjSheet.Range("C3")
    xlObjCell.Select
    celObj.Formula = xlObjCell.Value
End Sub


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint