Beginning Word Programming In VB
After objWord is set up and a instance of Word is established we will proceed to the cmdCreateADoc_Click event. This is where you should set you breakpoint on the first line of the second WITH statement. This is the upper level call to the Application Object of MS Word we created. We will be using WITH statements for several reasons. The most important are speed and good coding form. The speed comes from the fact that we dont have re-enter the application object as we nest into the instance of MS Word.
In a nutshell, these two lines of code are equal to leaving the store each time you buy something and going back in again to purchase another item.
For example:
ObjStore.PickItem.PayforItem.LeaveStoreObjStore.PickItem.PayforItem.LeaveStoreObjStore.PickItem.PayforItem.LeaveStore
This is better and easier to read:
With ObjStore.PickItem.PickItem.PickItem.PayforItem.PayforItem.PayforItem.LeaveStoreEnd With
What would you rather do?
Page 3 of 6
This article was originally published on November 20, 2002