1 / 11

Visual Basic Programming II Lecture 13

Visual Basic Programming II Lecture 13. MIS233 Instructor – Larry Langellier. This Week – Working with the MS Office Suite. Controlling Office Applications from VB Excel Object Model Controlling Excel programmatically Introduction to VBA in Office Applications

Download Presentation

Visual Basic Programming II Lecture 13

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic Programming IILecture 13 MIS233 Instructor – Larry Langellier

  2. This Week – Working with the MS Office Suite • Controlling Office Applications from VB • Excel Object Model • Controlling Excel programmatically • Introduction to VBA in Office Applications • Explore with the Macro Recorder • Using the Object Browser to explore object models

  3. Working with Objects from Microsoft Office • Microsoft Office Suite • Word • Excel (which we’ll focus on today) • Access • PowerPoint • Outlook/Exchange • Stand-alone Visual Basic applications can interact with the MS Office components • You can also use Visual Basic within an MS Office application (VBA) • The capabilities of MS Office products serve as useful add-ons to all kinds of programming tasks

  4. Controlling Office Apps from VB • MS Office Applications are implemented as ActiveX EXE servers • They contain a public object library that can be used by other applications • They can service multiple applications • The MS Office application can be running on a different machine • A single user-application can call on the services of more than one MS Office application

  5. Connecting to an MS Office application • Set a Project Reference • CreateObject() • Running an instance of Excel - Example 26.1 Dim xlapp As Excel.Application Private Sub cmdStart_Click() Set xlapp = CreateObject(“Excel.Application”) xlapp.Visible = True End Sub Private Sub cmdStop_Click() xlapp.Quit Set xlapp = Nothing End Sub

  6. Exploring with the Object Browser • Set a reference to an MS Office application • Open Object Browser

  7. Exploring with VBA Macros • Each MS Office application provides a VB development environment called Visual Basic for Applications • Let’s look at Macros in Excel • Macros.xls • Macro Edit • Extensive programming can be done directly inside of the Office application using VBA • Identical results can be achieved directly from Visual Basic also – using the ActiveX object wrappers provided for each MS Office Suite application

  8. The Excel Object Model • Application • ActiveSheet, ActiveCell • Workbooks, Worksheets • Visible • Width, Height, Top, Left • Run (Macro, args…) • Quit() • Workbooks • Count, Item • Add(), Open(), Close(), OpenText() • Workbook • ActiveSheet, Sheets, Name • Close()

  9. Excel Object Model (cont.) • Worksheet • Cells, Columns, Rows, Range • Name • Visible • Calculate() • Range • Formula, Value • EntireRow, EntireColumn • Name • NumberFormat, MergeCells, Orientation • Example • Exercise 26.4

  10. Excel Example • Let’s add an Excel Report to the Baseball 3-Tier Solution we’ve been developing for the past few weeks • Put the statistics for the players into an Excel Spreadsheet • Examples • Using Existing Macros • Calling existing Macros in a Excel Spreadsheet – Macros.xls • Reports Menu -> Format Existing Report • Programmatically from within Visual Basic • Using the Excel Object Wrapper • Reports Menu -> Team Hitting

  11. Details… • Next Class • Finals Week • Final Project Presentations • Attendance is required • Additional courses… • MIS288 – Visual Basic Software Development • MIS287 – Visual Basic for Applications • OSA257 – Database Management • MIS292 – SQL/Database Applications • Other Languages/Technologies • C++ • Java • Web • eCommerce

More Related