Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Try and catch ???

Try and catch ???

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    veon cheng
    wrote on last edited by
    #1

    hi to all, i would like to know whether VBA is able to perform try and catch, if there is. how am i suppose to code it thanks veon

    K 1 Reply Last reply
    0
    • V veon cheng

      hi to all, i would like to know whether VBA is able to perform try and catch, if there is. how am i suppose to code it thanks veon

      K Offline
      K Offline
      koolprasad2003
      wrote on last edited by
      #2

      there is no try catch like .NET but u can use OnError goto let's see with an example

      Private Sub Command1_Click()
      On Error GoTo ErrorHandler
      Error 424 'This error is displayed when there is a missing object
      Exit Sub
      ErrorHandler:
      MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
      End Sub

      this is how you can handle exceptions, errors in VB6 hope it helps... :)

      If the message is useful for U then please Rate This message... Be a good listener...Because Opprtunity knoughts softly...N-Joy

      V 1 Reply Last reply
      0
      • K koolprasad2003

        there is no try catch like .NET but u can use OnError goto let's see with an example

        Private Sub Command1_Click()
        On Error GoTo ErrorHandler
        Error 424 'This error is displayed when there is a missing object
        Exit Sub
        ErrorHandler:
        MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
        End Sub

        this is how you can handle exceptions, errors in VB6 hope it helps... :)

        If the message is useful for U then please Rate This message... Be a good listener...Because Opprtunity knoughts softly...N-Joy

        V Offline
        V Offline
        veon cheng
        wrote on last edited by
        #3

        hi thanks for your help but now i have a problem, i paste the your code into my code , when there is no error the error msgbox will prompt the user. this is how i code it

        Private Sub CommandButton3_Click()
        On Error GoTo ErrorHandler
        Error 424 'This error is displayed when there is a missing object
        Exit Sub
        Dim Wk As Worksheet
        Set Wk = Sheets.Add
        ss = tbx_name.Text
        Application.DisplayAlerts = False
        Wk.Name = ss
        ErrorHandler: MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
        End Sub

        so whats wrong with it thanks thanks veon

        K 1 Reply Last reply
        0
        • V veon cheng

          hi thanks for your help but now i have a problem, i paste the your code into my code , when there is no error the error msgbox will prompt the user. this is how i code it

          Private Sub CommandButton3_Click()
          On Error GoTo ErrorHandler
          Error 424 'This error is displayed when there is a missing object
          Exit Sub
          Dim Wk As Worksheet
          Set Wk = Sheets.Add
          ss = tbx_name.Text
          Application.DisplayAlerts = False
          Wk.Name = ss
          ErrorHandler: MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
          End Sub

          so whats wrong with it thanks thanks veon

          K Offline
          K Offline
          koolprasad2003
          wrote on last edited by
          #4

          Try following code

          Private Sub CommandButton3_Click()
          On Error GoTo ErrorHandlerError
          Dim Wk As Worksheet
          Set Wk = Sheets.Add
          ss = tbx_name.Text
          Application.DisplayAlerts = False
          Wk.Name = ss
          ErrorHandler:
          MsgBox "Error Number: " & Err.Number & " With The Description ->> " & Err.Description & " <<- Occured."
          End Sub

          hope it helps.... :)

          If the message is useful for U then please Rate This message... Be a good listener...Because Opprtunity knoughts softly...N-Joy

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups