Opening a Document

To open a document file, use the Open method of the Documents collection. The Open method has a dozen arguments you can use to fine-tune your document openings, but only one of these is mandatory. Here's the simplified syntax showing the one required argument (for the rest of the arguments, look up the Open method in the VBA Help system):

Documents.Open(FileName)

FileName The name of the document file, including the drive and folder where the file is located.

For example, to open a document named Letter.docx in the C:\Users\Paul\Documents folder, you would use the following statement: Documents.Open "C:\Users\Paul\Documents\Letter.docx"

^ Rather than hard-coding the path to your user profile's Documents folder in Windows Vista,you can use the expression Environ("UserProfile"),which returns the path to your user profile's main folder. So, in Vista,you'd use the following expression to return your Documents folder:

Environ("UserProfile") & "\Documents"

If you're using Windows XP, instead, replace Documents with My Documents.The Environ function (it's short for environment) returns the value of the Windows built-in environment variables. To see a list of these variables, choose Start, All Programs, Accessories, Command Prompt, type set at the command prompt,and then press Enter.

0 0

Post a comment