Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

Chapter 13 - Microsoft Office Applications and Managing Processes - Part 1

By Dan Mabbutt, About.com

8 of 9

The VSTO Code Example - Page 2

--->Code continued from the previous page
#Region "Generated initialization code"

  ' Called when the workbook is opened.
  Private Sub ThisWorkbook_Open() _
    Handles ThisWorkbook.Open
    ' Visual Basic
    Dim str As String
    str = "About Visual Basic"
    Dim mySheet As Excel.Worksheet
    Dim myRange As Excel.Range
    Try
      mySheet = _
        CType(Me.ThisApplication.Sheets.Item(1), _
        Excel.Worksheet)
      CType(mySheet.Cells.Item(2, 2), Excel.Range).Value _
        = "Hello From"
      CType(mySheet.Cells.Item(3, 2), Excel.Range).Value _
        = "About Visual Basic"
      myRange = mySheet.Range("B2:B3")
      myRange.Font.ColorIndex = 3
      myRange.Font.Bold = True
      myRange.Font.Size = 18
    Catch ex As Exception
      MsgBox("something didn't work: " & ex.Message)
    End Try
  End Sub
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~

Explore Visual Basic

By Category

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Automating Microsoft Office Applications and Managing Processes - Part 1

©2009 About.com, a part of The New York Times Company.

All rights reserved.