excel vba - VBA Error Handling to check for folder existence -


i'm trying implement 'error handling' existing script , i've put following:

edited code

private sub workbook_open()  dim j integer  application.screenupdating = false 'display splash form non-modally. set frm = new frmsplash frm     .taskdone = false     .prgstatus.value = 0     .startupposition = 0     .left = application.left + (0.5 * application.width) - (0.5 * .width)     .top = application.top + (0.5 * application.height) - (0.5 * .height)     .show false end  j = 1 1000     doevents     next j      irow = 17       fpath = "\\c\s\caf1\dragon mentor group\dragon scripts\current\april 2015\"     if fpath = vbnullstring goto errorhandler     if not dir(fpath, vbdirectory) = vbnullstring         on error goto 0         set fso = new scripting.filesystemobject         frm.prgstatus.value = 15         if fso.folderexists(fpath) <> false             frm.prgstatus.value = 30             set sourcefolder = fso.getfolder(fpath)             issubfolder = true             frm.prgstatus.value = 45             call deleterows             frm.prgstatus.value = 60                 call listfilesinfolder(sourcefolder, issubfolder)                 frm.prgstatus.value = 75             call formatcells             frm.prgstatus.value = 100             else         end if     end if     frm.taskdone = true     unload frm     imessage = msgbox("the list has been been updated!", vbokonly)      '******error handling******     errorhandler:           msgbox "the filepath not exist, please contact       administrator"     resume next     end sub 

in error handling, i'm trying check whether folder exists. if doesn't, instigate error message. if does, run rest of script.

the problem that, when file path exist, error handler activated i'm not sure why despite looking @ quite number of tutorials.

i wondered whether @ please , let me know i've gone wrong.

all, thank , guidance. wanted let know work colleague, i've come code shown below. many , kind regards. chris

private sub workbook_open()      dim j integer     dim fpath string      on error goto errhandler: 'display splash form non-modally.     set frm = new frmsplash     frm         .taskdone = false         .prgstatus.value = 0         .startupposition = 0         .left = application.left + (0.5 * application.width) - (0.5 * .width)         .top = application.top + (0.5 * application.height) - (0.5 * .height)         .show false     end      j = 1 1000         doevents         next j          irow = 17         fpath = "\\c\s\caf1\dragon mentor group\dragon scripts\current\"         if dir(fpath) = ""             set fso = new scripting.filesystemobject             if fso.folderexists(fpath) = false '' code run here if folder not exist                 goto errhandler             else                 set sourcefolder = fso.getfolder(fpath)                 issubfolder = true                 call deleterows '''''''' '' max number of files in folders , subfolders ''''''''                 xcur = 1 'set start value xcur here reset when recurssively calling listfilesinfolder                 xmax = sourcefolder.files.count                 each subfolder in sourcefolder.subfolders                     xmax = xmax + subfolder.files.count                     next subfolder ''                     call listfilesinfolder(sourcefolder, issubfolder) ''                     call formatcells                 end if             end if              frm.taskdone = true             unload frm 'the row below creates 'on screen' message telling user workbook has been built.             msgbox "the list has been been updated!"             exit sub '' errhandler:             frm.taskdone = true             unload frm             msgbox "the file path doesn't exist, please contact administrator", , "file path error" ''         end sub 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -