Files & Directories

If you want to work with files or the file system then there a various options available.
VBA Functions - These are the built-in functions and procedures.
File System Object - This uses an additional library called the Microsoft Scripting Run-time

Guidelines when working with Files and Folder

All folder conventions should be: \2010\February\2010_Feb_24.xls
Need generic code to always get a file from a folder and if the file does not exist then automatically search the "archive" sub folder.
All folder paths should be UNC standard \\server\share [never use mapped letters]
When opening files from folders always check for permission and if not display a sensible error message
Code to analyse a folder and get the data from the last saved down file.
Be able to look for previous dates in order.

File Attribute Constants

vbNormal0Normal, default for Dir & SetAttr
vbSystem4System file
vbVolume8Volume label
vbDirectory16Directory or Folder
vbArchive32File has changed since last backup ??
vbAlias64Identifier is an alias


When using strings of folderpaths and files they are not case sensitive
Always check the server folder is available first if not display a polite message
Always check the folder actually exists and check the access permission with sensible error messages if user does not have permission.
Always use the UNC folderpath classifications.
No hard typing of drive letters - always use full name ( \\server\path\ )
Never refer to mapped drives.
When using folders always check they exist and check the permission with sensible error messages.
The FileSearch object can be used as an alternative to using the Dir() function. This is available in Office 97, but has been enhanced significantly in Office XP.

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopNext