Error Message Dimming

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
If I want an error message such as "On error Goto Help" and then later "Help:"

I would just do that. however, Excel is making me dim "help". How would I do that? As a string works but isn't right I don't think.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It doesn't for me. See this simple example:
Code:
Option Explicit


Sub Test()

    Dim x As Long
    Dim y As Long
    
    x = 1
    y = 0

    On Error GoTo Help
    MsgBox x / y
    On Error GoTo 0
    
    Exit Sub
    
Help:
    MsgBox "ERROR!"
    
End Sub
I am guessing it might be how you wrote it. If you cannot figure it out, please post your code for us to see.
 
Upvote 0
Do you have the quotes round Help:?
 
Upvote 0
I've never had problems until this piece of code:
I took out the "Dim Helper As String" piece out of the top it kicks back "variable not defined"
OR it'll kick back if I don't have "resp" with the same message....
Code:
 Sub Print_Sheet()

'Begins Error Handling Code
On Error GoTo Helper


    Dim Mail As String
    Dim name As String
    name = Sheets("Notes").Range("N4")
    ActiveSheet.PageSetup.PrintArea = "$A$1:$O$55"
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    Application.PrintCommunication = True
    ActiveSheet.PageSetup.PrintArea = "$A$1:$O$55"
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.7)
        .RightMargin = Application.InchesToPoints(0.7)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = 600
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlPortrait
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .EvenPage.LeftHeader.Text = ""
        .EvenPage.CenterHeader.Text = ""
        .EvenPage.RightHeader.Text = ""
        .EvenPage.LeftFooter.Text = ""
        .EvenPage.CenterFooter.Text = ""
        .EvenPage.RightFooter.Text = ""
        .FirstPage.LeftHeader.Text = ""
        .FirstPage.CenterHeader.Text = ""
        .FirstPage.RightHeader.Text = ""
        .FirstPage.LeftFooter.Text = ""
        .FirstPage.CenterFooter.Text = ""
        .FirstPage.RightFooter.Text = ""
    End With
    Application.PrintCommunication = True
    'ActiveSheet.PrintOut
    
    If Sheets("Notes").Range("M30").Value = "Yes" Then
        Call Printer
    End If
    
    If Sheets("Developer").Range("D10").Value = "Yes" Then Call Email_Active_Sheet
    If Sheets("Notes").Range("D12").Value = "Yes" Then Call EmailActiveMaster
    If Sheets("Developer").Range("B12").Value = "Yes" Then Call EmailActiveEngineers


    If Sheets("Developer").Range("D10").Value = "Yes" Then GoTo Mail
    If Sheets("Developer").Range("D12").Value = "Yes" Then GoTo Mail
    If Sheets("Developer").Range("B12").Value = "Yes" Then GoTo Mail
    Exit Sub
Mail:
    MsgBox "The form has been emailed and should be coming out of the printer momentarily.", vbOKOnly, name
        
'Error Clearing Code
Exit Sub
Helper:
    resp = MsgBox("We're sorry to see you've encountered an error." & vbCrLf & vbCrLf & "To proceed, we recommend you contact the Developer " & _
    "with error codes [1144] and " & "[" & Err.Number & "-" & Err.Description & "]." & vbCrLf & vbCrLf & "To attempt to patch your problem at least " & _
    "temporarily, we recommend you click [Yes] to see help directions. Would you like to continue?", vbYesNoCancel, name)
        If resp = vbYes Then
            Call Error_Handle(sProcName, Err.Number, Err.Description)
        ElseIf resp = vbNo Then
            Exit Sub
        ElseIf resp = vbCancel Then
            Exit Sub
        End If
    
End Sub
 
Last edited:
Upvote 0
In testing your code, I cannot find any issue with the reference to the Error Handler called "Helper". However, you are using two undeclared variables in it, specifically "resp" and "sProcName".
Try declaring those and see if that fixes your issue.
 
Upvote 0
Resp would need to be String
As for sProcName, it's difficult to tell as it only appears once in your code & has no value
 
Upvote 0
Hmmm... Something was telling me that string was wrong. Ok. SProcname is going to be a string- it's the name of whatever module is producing the error as defined in another function. Still just working to figure out how to get the module coding itself to copy since I can copy the name of the module error'ing
 
Upvote 0
When in doubt, you can just declare it as variant (if you leave off the " As ..." part, it will also do that).
So, you could just do:
Code:
Dim resp
Before attempting to run your code at all, you should Compile it (under the "Debug" menu).
That will alert you of any obvious errors that will prevent your code from running, i.e. invalid arguments, certain typos, undeclared variables (if using "Option Explicit").
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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
Back
Top