October 23, 2016
Hot Topics:

Beginning Word Programming In VB

  • November 19, 2002
  • By Ronald Garlit
  • Send Email »
  • More Articles »

First we enter our Instance of Word.

With objWord

The first line is a call to the Documents collection object with the Add Method. This creates a blank document in MS Word. It automatically adds it to the documents collection.


Now we could just use the ActiveDocument for this whole program. But that would be bad form and there is a problem. First you could think of ActiveDocument as being Words own little ME Keyword. But every instance of Word has a ActiveDocument. Plus the instances have to share the document collection information. Word is an Automation Server (is that old lingo now?) It shares space in the registry and all kinds of other goodies mysterious and hidden. This is how you can open one copy of word and then another and one will have Document1 and the other Document2 and so on. Sound like fun yet. Hope we arent scaring you. So we are going to use Call by Name when we can and variables that reference our objects for control, clarity and speed.

Here we created a string variable to hold the name of the document we just created with the Add method.

strWorkingDocName = .ActiveDocument.Name

Next we set a reference to the document in the document variable aThatDoc by calling the document BY NAME (the one in the string variable).

Set aThatDoc = .Documents(strWorkingDocName)

We create another document and repeat the process again for the aThisDoc variable.

.Documents.AddstrWorkingDocName = .ActiveDocument.NameSet aThisDoc = .Documents(strWorkingDocName)

Page 4 of 6

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel