msgbox

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
I'd like an error handler on my code...i've never created one before so I'm not quite sure how to go about it. The following code copies a folder and renames it in a new directory. I'd like it to check to see if the new folder it is being named to already exists, and if so give you the option to cancel. Here is the code:

Code:
Sub copyFDfiles()

Dim myDir As String
Dim myDest As String
Dim fs As New Scripting.FileSystemObject

myDir = Range("C11").Value
myDest = Range("C12").Value

fs.copyfolder myDir, myDest
    
End Sub

The myDest part is where it creates the new folder...

Any ideas?

Thanks,

Dave M.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Courtesy John Walkenbach:

Code:
Private Function PathExists(pname) As Boolean
'   Returns TRUE if the path exists
    Dim x As String
    On Error Resume Next
    x = GetAttr(pname) And 0
    If Err = 0 Then PathExists = True _
      Else PathExists = False
End Function

More here:

http://j-walk.com/ss/excel/tips/tip54.htm
 

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
Thanks Andrew!! Great help as always!!

Have a great weekend! (y)

Dave M.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,161
Messages
5,768,542
Members
425,480
Latest member
br400821

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top