| VBA - Word and Excel Working Together | |||||||||||||||||||||||||
| Part 3: The Word Document VBA Code | |||||||||||||||||||||||||
The Open event does two things:
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 |
|||||||||||||||||||||||||

