Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3273690
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:57:31+00:00 2026-05-17T18:57:31+00:00

This is still related with my previous questions, VBA: How to display an error

  • 0

This is still related with my previous questions, VBA: How to display an error message just like the standard error message which has a “Debug” button?

Now, I successfully make the current cursor in VBE jump to a particular procedure in VBE. I used Application.Goto to achieve this. However, what actually I want is to make the current cursor in VBE jump to the line where the last error occured. I suspected there should be something useful for this purpose in Application.VBE object but didn’t know which?

Solving this also means satisfying my previous question entirely. Any hints or even dirty tricks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:57:31+00:00Added an answer on May 17, 2026 at 6:57 pm

    Continued from your previous question 🙂

    I suppose you are already using line numbering (as answered in the previous question).

    So, modify your error handling routine to something like:

    Sub aa()
    Dim zz As Long
    
    10:     On Error GoTo ErrorHandler
    20:     DivisionByZero = 1 / 0
    30:     Exit Sub
    ErrorHandler:
    41:  If Err.Number <> 0 Then
    42:     Msg = "Error # " & Str(Err.Number) & " was generated by " _
             & Err.Source & Chr(13) & "Error Line: " & Erl & Chr(13) & Err.Description
    43:     MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
            zz = CodeFind("", "", Str(Erl), 0)
    44:     End If
    50:     Resume Next
    End Sub
    

    Now for the CodeFind() thing. I found it here (at the bottom, the last one), but had to modify it a bit, so I’m posting a lot of code … sorry.

    Insert this code in a new module and be sure you have the reference to “Microsoft Visual Basic For Applications Extensibility 5.3” checked, and the project is not protected. In doubt see here.

    HTH!

    Here is the code

     Option Explicit
     '---------------------------------------------------------------------------------------
     ' Procedure : CodeFind
     ' DateTime  : 7/5/2005 18:32
     ' Author    : Nelson Hochberg
     ' Purpose   : Find a module, a procedure and/or a string in code and highlight it
     ' Returns   : 0 if not found,  line number in module if found
     ' Syntax    : lngReturn = CodeFind ([FindMod],[FindProc],[FindStr],[TypeOfSearch])
     ' Arguments : Optional FindMod As String: Part of a name of a module
     '             Optional FindProc As String: Part of a name of a procedure
     '             Optional FindStr As String: Part of a string to search
     '             NOTE: One of the above three is required
     '             Optional TypeOfSearch As Long: -1 Find line number, 0 Find string,
     '                      >0 Continue search starting at line number: TypeOfSearch + 1
     ' Thanks    : To stevbe at Experts Exchange for the initial code.
     '---------------------------------------------------------------------------------------
     '
     Public Function CodeFind( _
     Optional FindMod As String = "", _
     Optional FindProc As String = "", _
     Optional FindStr As String = "", _
     Optional TypeOfSearch As Long = 0 _
     ) As Long
    
     Dim vbc As VBIDE.VBComponent
     Dim cm As VBIDE.CodeModule
     Dim VBAEditor As VBIDE.VBE
     Dim VBProj As VBIDE.VBProject
    
    
     Dim startline As Long, startcol As Long, endline As Long, endcol As Long
    
     If FindMod <> "" Then
         CodeFind = FindModule(FindMod, vbc, cm)
             If CodeFind = False Then Exit Function
         If FindProc <> "" Then
             CodeFind = FindProcedure(FindProc, startline, startcol, endline, endcol, cm)
                 If CodeFind = False Then Exit Function
             If FindStr <> "" Then
                 CodeFind = FindString(FindStr, startline, startcol, endline, endcol, cm, TypeOfSearch)
                     If CodeFind = False Then Exit Function
             Else
                 GoTo CodeLineFound
             End If
         Else
             startline = 1
             If FindStr <> "" Then
                 CodeFind = FindString(FindStr, startline, startcol, endline, endcol, cm, TypeOfSearch)
                 If CodeFind = False Then Exit Function
             Else
                 GoTo CodeLineFound
             End If
         End If
     Else
         Set VBAEditor = Application.VBE
     '''''''''''''''''''''''''''''''''''''''''''
         Set VBProj = VBAEditor.ActiveVBProject
         For Each vbc In VBProj.VBComponents
    
    
             Set cm = vbc.CodeModule
             If FindProc <> "" Then
                 CodeFind = FindProcedure(FindProc, startline, startcol, endline, endcol, cm)
                 If CodeFind = False Then GoTo Nextvbc2 Else Exit For
             Else
                 startline = 1
                 If FindStr <> "" Then
                     CodeFind = FindString(FindStr, startline, startcol, endline, endcol, cm, TypeOfSearch)
                         If CodeFind = False Then GoTo Nextvbc2 Else Exit For
                 Else
                     MsgBox "CodeFind: At least one of the following is required:" & vbCrLf & _
                         "    Module" & vbCrLf & "    Procedure" & vbCrLf & "    String"
                     CodeFind = False
                     Exit Function
                 End If
             End If
     Nextvbc2:
         Next vbc
         If CodeFind <> False Then
             If FindStr <> "" Then
                 CodeFind = FindString(FindStr, startline, startcol, endline, endcol, cm, TypeOfSearch)
                 If CodeFind = False Then Exit Function
             Else
                 GoTo CodeLineFound
             End If
         End If
     End If
    
     CodeLineFound:
     If CodeFind <> False Then
         If endline = -1 Then endline = 1
         If endcol = -1 Then endcol = 1
         cm.CodePane.Show
         cm.CodePane.SetSelection startline, startcol, endline, endcol
     End If
    
     End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some previous questions related to this, but I'm still unable to solve
soryr this is still related to my previous thread but i created this new
Okay, this is quite related to my previous quesion , but still (so you
I have asked some questions related to this but have still no conclusive answers
This is related to another Delphi-version question but still different; I'm looking for a
Though it's on the edge of programming questions, I think this is still relevant
(This question is related to my previous question , or rather to my answer
This is related to my previous thread: SQL Query takes about 10 - 20
Related to this question and this answer (to another question) I am still unable
This is related to a previous question, and surprisingly, I couldn't find an example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.