Consulting

Results 1 to 4 of 4

Thread: destination name problem when error handeling... Please Help!!!

  1. #1

    destination name problem when error handeling... Please Help!!!

    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!

  2. #2
    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?

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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) <> "")

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I'd remove the ...

    On Error Goto Errhandler

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

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •