O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Final Note on VBA

There is a lot more to the VBA language than I have covered here. (In fact, the VBA reference manual is about 300 pages long.) However, I have covered the main points needed to begin Word VBA programming.

Actually, many Word VBA programming tasks require only a small portion of VBA’s features; you will probably find yourself wrestling much more with Word’s object model than with the VBA language itself.

I conclude our discussion of the VBA language per se with a brief outline of topics for further study, which you can do using the VBA help files.

File-Related Functions

VBA has a large number of functions related to file and directory housekeeping. Some of these are:

Dir

Find a file with a certain name

FileLen

Get the length of a file

FileTimeDate

Get the date stamp of a file

FileCopy

Copy a file

Kill

Delete a file

Name

Rename a file or directory

RmDir

Delete a directory

MkDir

Make a new directory

In addition to these file-related functions, there may be times when it is useful to create new text files (as opposed to Word files) to store data. VBA provides a number of functions for this purpose, headed by the Open statement, whose (simplified) syntax is:

	Open pathname For mode As [#]filenumber

Once a file has been opened, you can read or write to the file. I want to emphasize that opening files in this way creates text files, not Word documents.

Date- and Time-Related Functions

VBA has a large number of functions related to manipulating dates and times. Some of these ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required