PDA

View Full Version : destination name problem when error handeling... Please Help!!!



anne.gomes
05-22-2014, 03:48 PM
Hi,

For the line : MsgBox "The destination workbook is " & MyWorkbook.Name its saying destination workbook is Book2.xlsm. But when I put it inn, nothing happens and the code doesn't run. No error is thrown but nothing happens either.

Any ideas?




Sub Copy()

Dim MyWorkbook As Workbook

On Error GoTo Errhandler
ChDrive "C:"
ChDir "C:\"
ChDir "C:\test"

On Error GoTo 0
Set MyWorkbook = ActiveWorkbook
MsgBox "The destination workbook is " & MyWorkbook.Name
' Exit the macro so that the error handler is not executed.

Exit Sub

Errhandler:

Select Case Err
Case 68, 75: ' Error 68: "Device not available"
' Error 75: "Path/File Access Error"
MsgBox "There is an error reading drive C."
Case 76: ' Error 76: "Path not found"
MsgBox "The specified path is not found."
Case Else: ' An error other than 68, 75 or 76 has occurred.
MsgBox "Error # " & Err & " : " & Error(Err)

End Select

End Sub


Thanks in advance for your help! :)

westconn1
05-23-2014, 02:42 AM
But when I put it inn, nothing happens and the code doesn't run.do you get the messagebox?
what else is supposed to happen?

Kenneth Hobs
05-23-2014, 05:50 AM
What does, "put it inn", mean?

I would not use ChDrive or ChDir. Just set the path string and concatenate that if needed.

If your are using a Save or SaveAs, I would check that the path exists first before doing it rather than letting an error occur if the drive or path does not exist. e.g.

MsgBox "x:\test\ exists? " & CStr(Dir("x:\test\", vbDirectory) <> "")

Paul_Hossler
05-24-2014, 06:57 PM
I'd remove the ...



On Error Goto Errhandler



... and see what's failing and what the real error is