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:
Openpathname
Formode
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 ...
Get Writing Word Macros, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.