1. Home
  2. Computing & Technology
  3. Visual Basic
VBA - Word and Excel Working Together
Part 3: The Word Document VBA Code
 More of this Feature
• Part 1: Word and Excel Working Together
• Part 2: Designing the System
• Part 4: The Word Form
• Part 5: VBA Code Calling the Excel Server
• Part 6: The Final Result
 
 Join the Discussion
Have you created a system using VBA Automation ?
Tell us about it!
 
 Related Resources
• Beginning Visual Basic
• Visual Basic 6
 
 From Other Guides
• About Business Software
 
 Elsewhere on the Web
• An Excel VBA book
From the great publisher, APress

• Updates from Microsoft
(Browse to Office 2000)

 

The Open event does two things:

  • It adds all the phrases into listboxes for later use
  • It sets up the Windows form (named frmDocPhrases) and displays it

Once the Windows form is displayed, the rest of the code runs there.

Here's what the Open event code looks like:

Private Sub Document_Open()
    ' Salutation Phrases
    frmDocPhrases.lstSal.AddItem _
        "Valued Customer"
    frmDocPhrases.lstSal.AddItem _
        "Tough Nut"
    
    ' The remaining code to initialize
    ' the listboxes isn't shown here.
    ' See the downloaded source for
    ' complete code.
    
    frmDocPhrases.cmdSal_Click
    frmDocPhrases.Show
End Sub

A few comments about design and user interfaces: This example is not a model of excellent system or interface design. It's only intended to be a tutorial example and it has been kept as simple and uncomplicated as possible while still getting across the main points. For example, a real system would probably load the listboxes from a file or database and would likely have a satellite system that made it easy to update and change the phrases. In this example, we would have to change the VBA code - not a good design choice! And there are lots of other upgrades that a real system would have. This one doesn't have any error handling and a real one most certainly should have that.

Next page > The Word Form > Page 1, 2, 3, 4 5, 6
Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

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

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

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

All rights reserved.