Types of Errors
● Syntax/compile errors
● Runtime errors
● Logic errors
Run time errors:
● Two options
○ Ignore error
○ create special code to deal with the situation
● Option 1 - Ignore error
○ On Error Resume Next ‘turns on error handling
Appliation.DisplayAlerts = False
Code that may cause error goes here
On Error GoTo 0 ‘turns off error handling
● Display a message on error with Err Object
○ When an error occurs, an Err object is created
○ The default Number property of the built-in Err object has a nonzero value that an
If statement can check for.
○
● Option 2 - Handle the error/Write an Error Handler
, ○
○
■ In the label, if you want to return to the line after the one that caused the
error, use the statement Resume Next.
Chapter 13 - Working with Files and Folders
● Dialogue Boxes for File Operations
○ The FileDialogue object can be used to Open and Save different office file format
○ Different versions of FileDIalogue:
■ msoFileDialogOpen
■ msoFileDialogSaveAs
■ msoFileDialogFilePicker
● user can select multiple files
● All selected files are stored in the SelectedItems collection
■ msoFileDialogFolderPicker
● User select a folder from a dialog box
● Unless Cancel is clicked, the folder is stored it as
Selectedltems(1).
, ○
● The FileSystemObject Object
○ Used to check whether a file exists, rename a file, …. Etc
○ Declare FileSystemObject
■
○ Methods of FileSystemObject include: CreateFolder, CopyFolder, DeleteFolder,
CreateFile, DeleteFile, CopyFile, FileExists, and GetFolder
● Working with Text Files
○