Help with an error on the resume after an errhandler

Hayt

New Member
Joined
Aug 5, 2011
Messages
10
Hello,

I am getting an error on a line that just has resume on it after an errhandler

I have a workbook that I use to write invoices. Every time I open it, it adds 1 to the invoice number, saves the workbook, opens an input box that asks the user to enter the job name, then saves the workbook under a different name using the users input.

The problem is that some of our job names have an "/" in them, which causes an invalid file name.

To solve this I added an "on error" that would open another input box that states all the invalid characters and then asks the user to re-enter the job name then resumes on the line that saves the file.

when I do this I get an error on the resume and it either gives me an error or goes into an error loop and just keeps popping up the second input error box.

if I enter a valid name in the second input box, then it will save it with that name, then continue to pop the box up.

If i ad the line that saves the file to the errhandler, then the user only has one chance to enter the name without invalid characters, otherwise he gets an error message and i have to go fix the original workbook.

Here is the code I'm using

Code:
Private Sub Workbook_Open()

On Error GoTo errhandler:
If Range("I1").Value = "" Then



    Names("jobNumber").Value = Evaluate(Names("jobnumber").Value) + 1
    ThisWorkbook.Save
    Application.ScreenUpdating = False
  
    Dim strName As String

    strName = InputBox("Please Enter Job Name")
    ActiveWorkbook.SaveAs "C:\Users\Michael Guenter\Documents\Invoices\" & strName & " Invoice" & " " & Range("g6").Value & ".xls"
    On Error GoTo 0
  
    
    Range("b15").Value = strName
  ActiveWorkbook.RefreshAll
    
    Range("g5").Copy
    Range("g5").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    Range("I1").FormulaR1C1 = "x"
    Range("b16").Copy
    Range("b16").Selection.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    

    
    End If
Range("b13").Select

errhandler:

strName = InputBox("Job Name Cannot Contain \ / : * ? """" < >")

Resume

End Sub
Thank you,
Mike
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Code:
Private Sub Workbook_Open()

If Range("I1").Value = "" Then

    Names("jobNumber").Value = Evaluate(Names("jobnumber").Value) + 1
    ThisWorkbook.Save
    Application.ScreenUpdating = False
  
[COLOR="Red"]    Dim strName As String, FileName As String
Do
    strName = InputBox("Please Enter Job Name")
    If strName = "" Then Exit Sub 'User Canceled
    FileName = strName & " Invoice" & " " & Range("g6").Value & ".xls"
    On Error Resume Next
        ActiveWorkbook.SaveAs "C:\Users\Michael Guenter\Documents\Invoices\" & FileName
    On Error GoTo 0
    If ActiveWorkbook.Name <> FileName Then MsgBox FileName, , "Invalid File Name"
Loop Until ActiveWorkbook.Name = FileName[/COLOR]
    

  
    
    Range("b15").Value = strName
  ActiveWorkbook.RefreshAll
    
    Range("g5").Copy
    Range("g5").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    Range("I1").FormulaR1C1 = "x"
    Range("b16").Copy
    Range("b16").Selection.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    

    
    End If
Range("b13").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,073
Messages
6,053,381
Members
444,660
Latest member
Mingalsbe

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